Previous Thread:   SQL CLR Bug

2/12/2006 8:26:30 AM    Re: IsNullIfEmpty
Whether you should or should not expect a result from an empty table depends  
  
not on any property of the aggregate, but rather on your query and what's  
  
being grouped.  Take the following, for example:  
  
----  
  
create table #x(id int, id2 int)  
  
--Produces an empty set because there are no groups of id2 on which to  
  
aggregate  
  
select avg(id), id2  
  
from #x  
  
group by id2  
  
--Produces a NULL because you're treating the table as a single group  
  
select avg(id)  
  
from #x  
  
----  
  
Your user-defined aggregates will perform the same way.  IsNullIfEmpty is  
  
essentially a performance hint.  It tells the optimizer that if a particular  
  
group is empty -- that is, Accumulate has not been called -- that there is  
  
no need to call Terminate for the group.  The optimizer can simply set the  
  
output to NULL instead.  
  
--  
  
Adam Machanic  
  
Pro SQL Server 2005, available now  
  
http://www.apress.com/book/bookDisplay.html?bID=457  
  
--  
  
"Leila" <Leilas@hotpop.com> wrote in message  
  
news:uUcvCt5LGHA.3064@TK2MSFTNGP10.phx.gbl...



2/12/2006 9:39:56 AM    IsNullIfEmpty
Hi,  
  
I have problem with definition of property "IsNullIfEmpty" for  
  
"SqlUserDefinedAggregate attribute".  
  
I have created a UDA and I used it on an empty table. Should I expect to get  
  
Null when IsNullIfEmpty=True? I tried the aggregation for both True and  
  
False situation of IsNullIfEmpty but the results were the same (nothing  
  
appeared in the grid).  
  
Maybe I don't understand meaning of this property.  
  
Any help would be greatly appreciated,  
  
Leila