• vignesh.ms (9/2/2013)


    is there any other way ?

    This way is fine. It just needs to be modified slightly to handle nulls.

    [Code]

    Select a, b, c,

    case when isNull(a, getDate()-1000) >= isNull(b, getDate()-1000) and isNull(a, getDate()-1000) >= isNull(c, getDate()-1000) then a

    when isNull(b, getDate()-1000) >= isNull(c, getDate()-1000) then b

    else c end

    From sample

    [/code]

    Note: I pulled getDate()-1000 out of thin air. It just needs to be lower than any other date in your system. 0 does not work nor does casting it to date work. I am sure there is a more elegant way to check for a null date in this context, but this works.

    __________________________________________________________________________________________________________
    How to Post to get the most: http://www.sqlservercentral.com/articles/Best+Practices/61537/