How to keep null as blank in datetime data?

  • My asp.net program export a table to Excel in which null datetime data became "1/1/1900 12:00:00 AM" as default. How to keep null (blank) in stead of "1/1/1900 12:00:00 AM"?

  • I am not sure what method you are using to export the data, but one way is change the dates to an empty string when they are null.

    something like:

    select case when columnDate is NULL then '' else columnDate end as yourDate

    from table

    The probability of survival is inversely proportional to the angle of arrival.

  • I tested it but became 'Jan 1 1900 12:00AM'

  • adonetok (12/14/2010)


    I tested it but became 'Jan 1 1900 12:00AM'

    The reason is rather simple:

    Internally, SQL Server stores datetime values as two 4-byte integers (see BOL for details).

    A blank string assigned to an integer data type will be converted to Zero (0). And Zero (0) for a datetime value means '1900-01-01 12:00AM'.

    In order to replace NULL values with a blank you'd need to convert your result to a character data type first (using CONVERT). Then you can use ISNULL(converted_column,'').



    Lutz
    A pessimist is an optimist with experience.

    How to get fast answers to your question[/url]
    How to post performance related questions[/url]
    Links for Tally Table [/url] , Cross Tabs [/url] and Dynamic Cross Tabs [/url], Delimited Split Function[/url]

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

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