Convert date time stamp across multiple fields in case statement

  • Given the availability of collected data, I'm trying to combine multiple date fields into an Information Date, it seems to work but I'd like to drop the time stamp.

    case when completedDate is not null then completedDate   -- need to think about how to clean this up 
    when lastSavedDate is not null then lastSavedDate
    when receivedDate is not null then receivedDate
    else null end as infoDate,
  • Use COALESCE(completedDate ,lastSavedDate ,receivedDate )

    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.

  • convert(date,coalesce(completeddate,lastsaveddate,receiveddate),' ') [infoDate],

    Msg 8116, Level 16, State 1, Line 47

    Argument data type varchar is invalid for argument 3 of convert function.

    Was struggling with how to drop the time stamp, still not able to get there with coalesce

  • Check out the documentation for the CONVERT function.  The third argument has to be an integer, so ' ' is invalid.

    John

  • rickyschroder wrote:

    Was struggling with how to drop the time stamp, still not able to get there with coalesce

    TIMESTAMP columns cannot be converted to times. What is the data type of your source columns?

    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.

  • the three fields are datetime and I'd like to drop time

  • OK, then try

    CAST(coalesce(completeddate,lastsaveddate,receiveddate) as DATE)

    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.

  • TY Phil that git me to the finish line

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

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