Contrary of ISNULL() ?

  • Hello everyone,

    how can I display something when a specific field value is not null ?

    That of course wont work:

    SELECT *, ISNOTNULL(Authordate,'Last Upload: ') + ISNULL(Authordate,'') From Documents

    Any suggestions ?

    Sascha

  • SELECT < Column list >,

    CASE WHEN AuthorDate IS NULL THEN '' ELSE 'Last Upload: ' + CONVERT(VARCHAR(30), AuthorDate, < Appropriate formatting code >) END

    FROM Documents

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass
  • Same principal different code provided CONCAT_NULL_YIELDS_NULL is ON.

    SELECT ISNULL('Last Upload: ' + CONVERT(VARCHAR, AuthorDate+'', 112), '')

    FROM Documents

    Dave

  • Thank you both for your fast help, justanewone i used your solution its works fine ! 🙂

    Sascha

  • how can I display something when a specific field value is not null ?

    I see the examples of code folks gave you but they aren't really required. If the field is NOT null, it will display... no? Most systems will display a NULL as a blank and don't require a conversion to a blank or empty string. You'll save clock cycles in the process. 😉

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

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

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