|
Posted by --CELKO-- on 10/01/93 11:38
>> How to find first not null value in column without chacking whole table <<
Let's get back to the basics of an RDBMS. Rows are not records; fields
are not columns; tables are not files; there is no sequential access or
ordering in an RDBMS, so "first", "next" and "last" are totally
meaningless. If you want an ordering, then you need to havs a column
that defines that ordering. You must use an ORDER BY clause on a
cursor.
Next, you are talking about SQL as if you were in a file system, where
you read one record at a time and have explicit control flow via
procedural statements. That is also totally wrong; SQL is a
declarative, compiled language.
Let's make a guess, based on nothing you posted, as to what the DDL
looks like:
CREATE TABLE Foobar
(foo_key INTEGER NOT NULL PRIMARY KEY, -- order by him??
klugger INTEGER, -- target column ??
..);
SELECT foo_key
FROM Foobar
WHERE klugger IS NULL
AND foo_key
= (SELECT MIN(foo_key) FROM Foobar);
(if there is a not null value then show me it and stop searching, the
table is quite big)?
Show you the NULL value that does not exist? That makes no sense.
Neither does "stop searching", since SQL is a set-oriented language.
You get the entire result set back; it can be empty or it can have any
number of rows.
You need to read a book on RDBMS basics. You have missed the most
important concepts.
If there is no NULL in klugger, then yuou will get an empty set back.
Navigation:
[Reply to this message]
|