|
Posted by Hugo Kornelis on 02/01/06 00:17
On 30 Jan 2006 17:23:05 -0800, --CELKO-- wrote:
>I meant to put klugger in the outermost SELECT list. Arrgh!
Hi Joe,
Really? Your SQL skills are rapidly declining then...
You posted:
>>SELECT foo_key
>> FROM Foobar
>> WHERE klugger IS NULL
>> AND foo_key
>> = (SELECT MIN(foo_key) FROM Foobar);
So, from the remark above, I conclude that you meant to post
SELECT klugger
FROM Foobar
WHERE klugger IS NULL
AND foo_key
= (SELECT MIN(foo_key) FROM Foobar);
However, Martin's requirement was:
>>> How to find first not null value in column without chacking whole table <<
Your first query will either return the first (based on alphabetic
ordering) foo_key, unless klugger in that row is not NULL (in which
case, nothing is returned).
Your second query will return NULL if klugger in the first row (based on
alphabetic ordering of foo_key) is NULL, or nothing otherwise.
To find the first (based on alphabetic ordering) non NULL value is just
as simple as
SELECT MIN(klugger)
FROM Foobar
WHERE klugger IS NOT NULL
--
Hugo Kornelis, SQL Server MVP
[Back to original message]
|