re select where... please read this not previous 3

  • I have a table

    date     datetime

    text1    nvarchar

    text2    nvarchar

    I am running the following code

    select CONVERT(VARCHAR(8),date)) + ',' +

         text1 + ','

    from table;

    which returns

    Jan 26,abcdefg,

    When I add text2 to the select statement, which at this moment in time contains NULL, it simply returns the following

    NULL

    what I would like to see is

    Jan 26,abcdefg,NULL

    Can anyone please advise how I can get all values out of the table regardless of their value, in the format I have described.

    thanks

  • Have you looked at using ISNULL?

    select CONVERT(VARCHAR(8),date)) + ',' +

         ISNULL(text1, 'NULL') + ',' + ISNULL(text2, 'NULL')

     



    Shamless self promotion - read my blog http://sirsql.net

  • The problem you are running into is common.  ANYTHING + NULL will always = NULL.

    Nicholas has provided how to get around this by changing a NULL field to be a string field with a value of "NULL"



    Good Hunting!

    AJ Ahrens


    webmaster@kritter.net

Viewing 3 posts - 1 through 2 (of 2 total)

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