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 )

    The absence of evidence is not evidence of absence
    - Martin Rees
    The absence of consumable DDL, sample data and desired results is, however, evidence of the absence of my response
    - Phil Parkin

  • 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?

    The absence of evidence is not evidence of absence
    - Martin Rees
    The absence of consumable DDL, sample data and desired results is, however, evidence of the absence of my response
    - Phil Parkin

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

  • OK, then try

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

    The absence of evidence is not evidence of absence
    - Martin Rees
    The absence of consumable DDL, sample data and desired results is, however, evidence of the absence of my response
    - Phil Parkin

  • 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