• Phil Parkin - Thursday, February 23, 2017 11:10 AM

    mcfarlandparkway - Thursday, February 23, 2017 10:58 AM

    SELECT MAX(CASE code WHEN 'sdt' THEN convert(datetime,Cval) ELSE NULL END) as MinDate,

    MAX(CASE code WHEN 'Edt' THEN convert(datetime,Cval) ELSE NULL END) as MaxDate

     from table

    Cval in table is varchar(20). value holds in this column is '2015034' Now I have to compare this coulm value to datetime valve for that in the query how Cval column will be converted to datetime?

    If I had to convert 2015034 to a date, I wouldn't have a clue how to do it. Can you explain?

    Wonder if its a year and some form of Julian date, possibly where 034 is representing the day of the year.

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)