Groups | Blog | Home
all groups > sql server mseq > june 2004 >

sql server mseq : Dealing with Nulls, - use previous record


Kole
6/22/2004 12:09:08 PM
Do u know of a function that will return a field from the
previous record if the current record's field is null? I
know this is available in Monarch, but do not know how to
do it in SQL Server.
Hugo Kornelis
6/22/2004 10:28:36 PM
[quoted text, click to view]

Hi Kole,

Define "previous".

A relational table is, by definition, an UNordered collection of rows.
There is no such thing as a "previous" row. If you mean something like
"the row with the most recent changedate before the changedate of the
current row", or "the row with the largest PK value smaller than the PK
value of the current row", then you are talking in relational terms.

There is no standard function that will do this. You could use COALESCE,
combined with either a subquery or a self-join. If you need more help,
you'll have to provide more information first:

* DDL (CREATE TABLE statements, including all constraints) for all
relevant tables. Columns that are not related to the problem may be
omitted; if in doubt, leave them in.
* Sample data (as INSERT statements) that illustrates your problem.
* Expected output based on the provided sample data.
* An explanation of the expected output in relation to the sample input
data (e.g. what calculations are used, etc.)
* A description of the business problem you're trying to solve.

Best, Hugo
--

AddThis Social Bookmark Button