date time

  • I have a table that I am using to track a users progress on a set of forms. The rows are datetime format. I would like to test if a field is null, and if it is display a 0 otherwise a 1. I tried ISNULL(step1, 0) AS Step1 but it returns 1/1/1900 instead of a 0. Is there a way to test this so I can get a 0 for null? If there is no date in the field then the user has not started that step yet.

  • Please don't multipost:

    http://www.sqlservercentral.com/forums/shwmessage.aspx?forumid=4&messageid=186799

    --
    Frank Kalis
    Microsoft SQL Server MVP
    Webmaster: http://www.insidesql.org/blogs
    My blog: http://www.insidesql.org/blogs/frankkalis/[/url]

  • SELECT CASE WHEN Step1 IS NULL THEN 0 ELSE 1 END

    This will return the row as integer.

    In your case it shows 1/1/1900 because it transforms that integer 0 to SMALLDATETIME which is the type returned by you

     


    Kindest Regards,

    Vasc

  • This is how I tried to do it, but it didn't work.

    I don't understand how to use Case?

    Select ISNULL(MySurvey_Started, 0) As SurveyStarted, ISNULL(Start_User_Information, 0) As Step1, ISNULL(Start_Dependents, 0) As Step2

    FROM dbo.MySurvey_Progress

    Where User_ID = @ClientID

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

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