Null

  • How do I indicate durring selection that if something is null then it should be a 1 or a 0?

    if example IS NULL then 1 Else example


    "The grass is always greener over the septic tank." ~Leaf

  • SELECT ISNULL( example, 1 ) FROM MyTable

    Less ideal:

    SELECT case when example IS NULL then 1 else example end AS example FROM MyTable

    Those are the basics. ISNULL() is much preferred unless there are more conditions to check in addition to NULL.

  • alternatively if you want to check for more than 1 value. You could use a CASE statement. Check BOL for the correct syntax.

     

     -- Alex

     

  • You can use COALESCE function also..

    Select COALESCE(fieldName, 1) from myTable

    - Kamlesh

  • FYI, COALESCE is a simplyfied version/flavor of the CASE statement (for more info see BOL).

Viewing 5 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply