how to write getdate function with isnull

  • isnull(A.Account_Established_Date, CONVERT(nvarchar(23), GETDATE(), 121))

    is giving me:

    2008-11-12

    but i need to look like this:

    2008-11-12 10:23:43.600

    when i run this way it works:

    CONVERT(nvarchar(23), GETDATE(), 121)

  • Assuming that Account_Established_Date is defined as a datetime datatype, what happens when you use this:

    isnull(A.Account_Established_Date,gedate())

  • i get this:

    Nov 12 200

  • Appears that A.Account_Established_Date is not defined as a datetime, but perhaps nvarchar(10). Try this:

    coalesce(A.Account_Established_Date, CONVERT(nvarchar(23), GETDATE(), 121))

  • Here is some test code for you to check out.

    declare @SDate nvarchar(10),

    @SDateNull nvarchar(10),

    @DDate datetime;

    set @SDate = N'2008/10/12';

    set @DDate = getdate();

    select

    @SDate,

    @SDateNull,

    @DDate,

    isnull(@SDateNull,@DDate),

    coalesce(@SDateNull,@DDate);

    On my system, this is what was returned from the above:

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

    2008/10/12 NULL 2008-11-12 10:34:05.233 Nov 12 200 2008-11-12 10:34:05.233

    (1 row(s) affected)

  • thanks

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

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