Forum Discussion

ahamed0820's avatar
ahamed0820
Copper Contributor
Jan 13, 2024

Incorrect Result Set

Hi All Please explain why the first select statement returns the data when there is no available record in the table  Declare @Temp Table (EmployeeName Varchar(100),DOB Datetime) Select 'Test'...
  • LainRobertson's avatar
    Jan 13, 2024

    ahamed0820 

     

    The results are correct because you are using an aggregate function, which allows the 'Test' literal to generate a result set row that just happens to have a NULL value for the aggregate result.

     

    If you were not performing an aggregation - as shown in the following example, you would get no rows (which is what you seem to have incorrectly expected for the aggregate scenario).

     

    SELECT 'Test', * From @Temp;

     

    Cheers,

    Lain

Resources