Reply to Re: How to find first not null value in column

Your name:

Reply:


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]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация