Select and replace field NULL

  • Hello,

    In my result, I want to replace NULL by 0 in my query.

    Exemple :

    Nom         SUM

    --------------------------

    Michel       99,9

    Sandra      NULL

    Julie         49

    I would like this result :

    Nom         SUM

    --------------------------

    Michel       99,9

    Sandra      0

    Julie         49

     

    Thanks


    Kindest Regards,

    degrem_m
    Degremont

  • look up isnull function in bol.

  • Thanks


    Kindest Regards,

    degrem_m
    Degremont

  • And/Or set a default.

    ALTER TABLE tablename

    ADD CONSTRAINT columnname_default

    DEFAULT 0 FOR columnname

  • If NULL is a legitimate value ie. (NO VALUE), 0, 1, 2 you can use the COALESCE function to get the result your looking for. ie. the following example return's eight when Field1 is null

     

    SELECT

     

       [Name],

       COALESCE( [Field1], 8 )

     

    FROM

     

       TABLE

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

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