Getting Started with Adobe After Effects - Part 6: Motion Blur

Upload Image Close it
Select File

Browse by Tags · View All
sql_server 217
t-sql 211
tsql 116
sqlserver 96
BRH 78
#SQLServer 66
#TSQL 56
SQL Server 34
function 11

Archive · View All
August 2007 17
August 2010 8
June 2012 7
June 2011 7
November 2007 7
August 2012 6
May 2012 6
November 2011 6
August 2011 6
October 2011 6

Madhivanan's TSQL Blog

Aggregate functions always return at least a row although table is empty

Nov 22 2011 3:53AM by Madhivanan   

There are many aggregate functions available in SQL Server. One thing that most of the people forget is that Aggregate functions always return atleast a row no matter if there are rows in the table or where clause returns or does not return any resultset

Consider the following example

declare @t table(i int)
select i from @t

The above does not return any row as the table is empty. But note that when you use aggregate functions like below, they do return a single row. Run the following code and see the result

select max(i) from @t 
select count(i) from @t 
select Min(i) from @t 
select sum(i) from @t 
select var(i) from @t 

They are all returning a single row. So do not use aggregate functions to check for the existance of data.

Consider the following code

declare @t table(i int)

if exists(select i from @t)
select 'yes'
select 'no'

if exists(select max(i) from @t)
select 'yes'
select 'no'

The first query returns no whereas the second query returns yes. So be aware of this and use aggregate functions effectively

Tags: t-sql, sql_server, sqlserver, tsql, SQL Server, function, #SQLServer, aggregate,

2 · 40% · 13039



  • Nice fact about aggregate functions sql server.. I was not aware of it... Thanks for sharing

    commented on Nov 22 2011 5:14AM
    Suvendu Shekhar Giri
    173 · 1% · 289

Your Comment

Sign Up or Login to post a comment.

"Aggregate functions always return at least a row although table is empty" rated 5 out of 5 by 3 readers
Aggregate functions always return at least a row although table is empty , 5.0 out of 5 based on 3 ratings
    Copyright © Rivera Informatic Private Ltd Contact us      Privacy Policy      Terms of use      Report Abuse      Advertising      [ZULU1097]