Refer following query:
SELECT SUM(n) AS SUMVAL FROM (values(3),(4)) AS tbl(n) WHERE 1=0
Since I am providing a predicate that is false, i would have assumed it to return a empty result set(0 rows). But it returns a row with NULL. Is it a bug? Or is there a valid explanation for this behavior.
If I remove the aggregate function, I get a empty result set as expected:
SELECT n AS VAL FROM (values(3),(4)) AS tbl(n) WHERE 1=0
And just to make it clear, if I remove the false predicate, then the query will return 2 rows with values 3 and 4 for column 'VAL'
SELECT n AS VAL FROM (values(3),(4)) AS tbl(n)
But if I am using aggregate functions with GROUP BY clause, as shown in query below, i get expected result(empty rowset)
SELECT id, SUM(n) AS SUMVAL FROM (values(1,3.0),(2,4.0)) AS tbl(id,n) WHERE 1=0 GROUP BY id