Creating View with some some data logic

  • Okay, here is my problem and I can't figure it out. I'm sure it has a simple solution. I've never came across this problem before.

    I am trying to create a view. To simplify the explanation, let's just deal with one row. The column involved are Bill_Date, Status, Date1, Date2, Date3, Date4, Date5. Bill_Date should have "a" date in it (either date1, Date2... or Date 5 ) and we are creating this colomn in view.

    So here is the what i'm trying to do. Check Status coloumn first if has values "active" or "zero bal". If Status has those values, then insert Date1..... if Date1 is null, then insert date2... if Date2 is null, then insert Date3........upto Date5, otherwise insert "1/1/07".

    Any ideas??

    Thanks.

    Ravi.

    ------------
    🙂

  • If I follow your instructions correctly would this be close to what you would need:

    select

    Bill_Date,

    [Status],

    COALESCE(DATE1,DATE2, DATE3,DATE4,DATE5, '1/1/07') AS 'THIS DATE'

    from Test

    where [Status] in ('active','zero bal')

  • Thanks. It helped.

    ------------
    🙂

Viewing 3 posts - 1 through 2 (of 2 total)

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