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'
else
select 'no'
if exists(select max(i) from @t)
select 'yes'
else
select 'no'
The first query returns no whereas the second query returns yes. So be aware of this and use aggregate functions effectively