Re: Dealing with Nulls, - use previous record
From: Hugo Kornelis (hugo_at_pe_NO_rFact.in_SPAM_fo)
Date: 06/22/04
- Previous message: Hugo Kornelis: "Re: Using Stored Procedure returned fields in another Stored Proc or Query"
- In reply to: Kole: "Dealing with Nulls, - use previous record"
- Messages sorted by: [ date ] [ thread ]
Date: Tue, 22 Jun 2004 22:28:36 +0200
On Tue, 22 Jun 2004 12:09:08 -0700, Kole wrote:
>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.
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
-- (Remove _NO_ and _SPAM_ to get my e-mail address)
- Previous message: Hugo Kornelis: "Re: Using Stored Procedure returned fields in another Stored Proc or Query"
- In reply to: Kole: "Dealing with Nulls, - use previous record"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|
|