How to convert sql server default date value to NULL

  • Hi,

       I am facing a proble.When I enter space in date field in sql server ,it by default takes 1900-01-01 00:00:00.000.I want when I enter space in date field it will take NULL , not 1900-01-01 00:00:00.000.

    Can anyone tell me how to get this??

    Thanks & Regards

    Niladri Saha

     

  • SQL Server recognises a space as being different from a null (because it is).  Why don't you just configure your app to convert a space to a null and write that to SQL Server?

    If you haven't even tried to resolve your issue, please don't expect the hard-working volunteers here to waste their time providing links to answers which you could easily have found yourself.

  • It is not related to any application.I am concer about this when I am entering any data from backend.In that case if I give space in datetime column it takes SQL Server default date.I want to change that.

    Thanks

    Niladri Saha

  • Using EM to input data, CTRL/0 will enter a NULL for you.

    If you are really concerned, I guess you could write a trigger that will always convert space to NULL, but seems a bit unusual.

    If you are entering new rows, why not just default the date to NULL?

    If you haven't even tried to resolve your issue, please don't expect the hard-working volunteers here to waste their time providing links to answers which you could easily have found yourself.

  • USE THIS QUERY :

    IN THIS QUERY

    MYTAB_DATE IS A TABLE WHICH CONTAINS SQL DEFAULT DATE 

    UPDATE MYTB_DATE SET DT=NULL WHERE DT=CONVERT(DATETIME,' ')

  • in the insert use case statement

     

    insert my_table(col1)

    select case when len(date1_char) = 0 THEN NULL ELSE cast(date1_char as smalldatetime)

    Leah Kats

  • NULLs are not generally a very good choice as a Default.  You may want to consider accepting the 1900 date as NULL does not equal NULL and NULL has numerous meanings when interpretting the data, (i.e., did you not have a data at the time of entry and will get one later, will there never be a date, etc...). 

    Just my $0.02. 

     

    I wasn't born stupid - I had to study.

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

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