ISNULL(date,'-')

  • hi

    I am new to SQL

    i wanted to know,

    how can i show date as '-' when it is NULL or EMPTY in the database ?

    thanks...

  • Do it on the application side, you don't need to do it in SQL.

    -- Gianluca Sartori

  • Gianluca Sartori (9/1/2009)


    Do it on the application side, you don't need to do it in SQL.

    Totally agree.

    However, if you insist on doing it in SQL you can do it in several ways, here are four:DECLARE @MyDate DATETIME

    --SET @MyDate = CURRENT_TIMESTAMP

    SELECT

    COALESCE(CAST(@MyDate AS VARCHAR(25)), CAST('-' AS VARCHAR(25))) AS Method1,

    COALESCE(CONVERT(VARCHAR(25), @MyDate, 103), CAST('-' AS VARCHAR(25))) AS Method2,

    CASE

    WHEN @MyDate IS NULL THEN CAST('-' AS VARCHAR(25))

    ELSE CAST(@MyDate AS VARCHAR(25))

    END AS Method3,

    CASE

    WHEN @MyDate IS NULL THEN CAST('-' AS VARCHAR(25))

    ELSE CONVERT(VARCHAR(25), @MyDate, 103) -- Or other format

    END AS Method4

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

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