DateTime query

  • How is it possible for a datetime field to be blank or null if not entered?

    currently if no valid date added, sql server adds a default date (01/01/1900) but i want to know how to have no entry

     

    anyone know?

     

  • It seems that you have a default constraint on that column. Remove the constraint and alter the column to accept Nulls.







    **ASCII stupid question, get a stupid ANSI !!!**

  • Are you sure your front-end doesn't enter a 0 into the column?

     

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

  • As Frank mentioned your front end is most likely passing in some default value so just explicitly set the date to NULL when the user has not entered a date.

    Edit: You left it up to the computer to decide??

  • Hi Mark,

    Date field allows nulls but make sure that your front end doesnt pass any default date values

  • Just to add.

    Even if you don't supply a numeric value like 0, an empty string will also cause the 19000101 date in a date column:

    select cast('' as datetime)

                                                          

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

    1900-01-01 00:00:00.000

    (1 row(s) affected)

    If you can live with that default, I wouldn't change it. Makes life easier not to deal with NULL logic.

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

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

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