Results 1 to 4 of 4
  1. #1
    Join Date
    Dec 2002
    Location
    Antwerp, Belgium
    Posts
    227

    Question Unanswered: choosing a the column that is not null

    I have two columns in a table. For every record, one column contains a value and the other one is null. Which one is filled and which one is empty differs per record. In my query I only want to retrieve the column that contains the value, but not the other one. Is it possible to do this with a standard tsql function? Other solutions are also welcome.
    Johan

  2. #2
    Join Date
    Aug 2002
    Location
    Scotland
    Posts
    1,578
    REfer IS [NOT] NULL from BOL.
    --Satya SKJ
    Microsoft SQL Server MVP
    [IMG]http://sqlserver-qa.net/google_bart.gif[/IMG]

  3. #3
    Join Date
    Dec 2002
    Location
    Antwerp, Belgium
    Posts
    227
    I tried to use "is null", "not null" and stuff like that, but it did not get the desired results. Meanwhile I found the functions "ISNULL()" and "NULLIF()". As I can see it now, these provide the correct results.
    Johan

  4. #4
    Join Date
    Apr 2003
    Location
    UK
    Posts
    11

    Lightbulb

    Originally posted by jora
    I tried to use "is null", "not null" and stuff like that, but it did not get the desired results. Meanwhile I found the functions "ISNULL()" and "NULLIF()". As I can see it now, these provide the correct results.
    You might want to take a look at the function COALESCE() which is designed to solve the problem you have.

    The function is also part of the ANSI standard and is supported by many RDBMS.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •