Re: Dealing with Nulls, - use previous record

From: Hugo Kornelis (hugo_at_pe_NO_rFact.in_SPAM_fo)
Date: 06/22/04

  • Next message: baz: "IIF in where clause to exclude selection criteri when null"
    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)
    

  • Next message: baz: "IIF in where clause to exclude selection criteri when null"

    Relevant Pages

    • Re: How to synch up values from multiple tables into a single row
      ... The expected output, based on the sample data provided. ... any SQL code you are already using, ... getting from it (if it's an error message: ...
      (microsoft.public.sqlserver.programming)
    • Re: Extremely complicated problem :(
      ... >their associated charges, payments and adjustments + the payer name ... If you do want help writing the query, ... Sample data that is illustrative of your problem. ... Expected output, based on the sample data given; ...
      (microsoft.public.sqlserver.programming)
    • Re: Query for search engine
      ... > relational database and is not restricted to SQL server. ... > our internet site and SQL for our intranet sites. ... >> Could you please post some DDL, sample data and expected result? ...
      (microsoft.public.sqlserver.programming)
    • Access SUMs Full Column When Using Subquery
      ... I jumped over to SQL Server, and it gave me the results I wanted, so ... Sample Data: Students_02272005_1 ... SELECT clause due to conditions specified on the subquery's WHERE ... Stud_ID Lesson PercentAbove5 ...
      (microsoft.public.access.queries)
    • Re: UDF and SQL2000 - Why doesnt this work?
      ... Basically This is what I want to do - I have created a query ... as DDL (i.e. CREATE TABLE statements; ... Sample data that illustrates the problem, ... Expected output from the sample data supplied; ...
      (microsoft.public.sqlserver.programming)