Replace datetime column with null as empty string

  • hi,

    I have a query as below

    select ISNULL([HIRE_VEHICLE_REGISTERED_DATE],'') from WIP_INVOICE_HEADER

    This returns the output as 1900-01-01. But i need an empty string if the value in the column is null.

    how can i get that?

    Please help....

  • You will need to convert the column to a string.

    If you tell SQL to use '' as a datetime column you will get 1900-01-01 as that is the default date and the default way SQL works.

  • Hi

    If you see my entire sql it will be a coalesce of many columns. In that one is a datecolumn and i do the following

    COALESCE(CAST(ISNULL(IH.[HIRE_VEHICLE_REGISTERED_DATE],'')AS VARCHAR) + ',', '')

    When i do export,

    Only empty values were comma sepearted and null values are not.

    so i do a null check and to replace all null values with empty string.

  • Convert the column before doing the ISNULL check

    ISNULL(CONVERT(varchar, datecolumn),'')

  • Thanks 🙂 it worked

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

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