bitbucket-25253 (2/16/2010)
Juan de Dios (2/16/2010)
--------------------------------------------------------------------------------
This script is very useful when all the rows are not NULL, but if you modify the insert of Mark with NULL, the script only returns Bill.
insert into @table values (4, NULL,'M')
Result: Bill
Where John goes???
stewartc-708166
To cate for this, an aditional clause should be added to the predicate, viz:
AND Name IS NOT NULL
In addition or an alternative to stewartc excellent suggestion, you can in effect negate the presence of the NULL by using an ORDER BY [name] clause
More interesting try the code with a BLANK name, without the ORDER BY clause it appears in the list of names as , ,
- with the ORDER BY clause it appears as a leading comma before Bill.
sanbornd
An EXCELLENT QOD thanks for devising it and submitting, may I encourage you to submit additional QODs
If you used this in the where clause AND ISNULL([name],'') <> '' you will negate both of the issues above.
A very good QOD which I have used a couple of times, but should be able to use more often