|
database
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Aggregate Functions - and no recordsIs the following statement documented/supported?
I can't find it documented in BOL the results for Aggregate functions when there is no input data. If a Aggregate function gets 0 records input, it returns null. eg. SELECT MAX( Field ) AS ReturnsNull FROM ( SELECT TOP 0 1 AS Field ) NoRecords Rebecca York (rebecca.york {at} 2ndbyte.com) writes:
Show quote > Is the following statement documented/supported? It is actually in Books Online, but it was not too easy to find it. Try> I can't find it documented in BOL the results for Aggregate functions when > there is no input data. > > > If a Aggregate function gets 0 records input, it returns null. > > eg. > > SELECT > MAX( Field ) AS ReturnsNull > FROM > ( > SELECT TOP 0 1 AS Field > ) NoRecords Accessing and Changing Relational Data Query Fundamentals Advanded Query Concepts Using Aggregate Functions Null Values Here is says: If no rows meet the condition(s) specified in the WHERE clause, COUNT returns a value of zero. The other functions all return NULL. COUNT(*), counts each row, even if all column values are NULL. -- Erland Sommarskog, SQL Server MVP, esq***@sommarskog.se Books Online for SQL Server SP3 at http://www.microsoft.com/sql/techinfo/productdoc/2000/books.asp Phew :)
Show quote "Erland Sommarskog" <esq***@sommarskog.se> wrote in message news:Xns96F6808DFCEA4Yazorman@127.0.0.1... > Rebecca York (rebecca.york {at} 2ndbyte.com) writes: > > Is the following statement documented/supported? > > I can't find it documented in BOL the results for Aggregate functions when > > there is no input data. > > > > > > If a Aggregate function gets 0 records input, it returns null. > > > > eg. > > > > SELECT > > MAX( Field ) AS ReturnsNull > > FROM > > ( > > SELECT TOP 0 1 AS Field > > ) NoRecords > > It is actually in Books Online, but it was not too easy to find it. Try > Accessing and Changing Relational Data > Query Fundamentals > Advanded Query Concepts > Using Aggregate Functions > Null Values > > Here is says: > > If no rows meet the condition(s) specified in the WHERE clause, COUNT > returns a value of zero. The other functions all return NULL. COUNT(*), > counts each row, even if all column values are NULL. |
|||||||||||||||||||||||