If else Query help

  • Hi Guys

    here is my sample table

    Area Days StartDate EndDate

    A 4 1/1/2004 ?

    B 5 20/04/2002 ?

    C 123 1/1/2006 ?

    I need to populate the EndDate column is such a way:

    If start date is > 1/1/2003, End date = Startdate + Days

    If start date < 1/1/2003, End date = '1/1/2003'-start date + Days

    How do I do this guys??

    Thanks

  • If start date < 1/1/2003, End date = '1/1/2003'-start date + Days

    I am a bit confused here. What do you mean EndDate = '1/1/2003' - startdate + Days? Can you give me what the resulting dates would be using your sample data?

    John Rowan

    ======================================================
    ======================================================
    Forum Etiquette: How to post data/code on a forum to get the best help[/url] - by Jeff Moden

  • Hi

    Here is the sample data

    Start date Days Enddate

    12/12/2004 12 14/12/2004

    1/1/2000 10 (1/1/2003-1/1/2000)+1

  • Whoa, hold on here my friend. How are you comming to your first end date? There is no 14th month! I thought from your original post that your data should look like this?

    StartDate Days EndDate

    12/12/2004 12 12/24/2004

    1/1/2000 10 ??

    What date would you put in the second EndDate?

    John Rowan

    ======================================================
    ======================================================
    Forum Etiquette: How to post data/code on a forum to get the best help[/url] - by Jeff Moden

  • UPDATE TableName

    SET EndDate =

    CASE

    WHEN StartDate > '2003/01/01' THEN DATEADD(day, Days, StartDate)

    WHEN StartDate < '2003/01/01' THEN ??? ((1/1/2003-1/1/2000)+1) is what date? why not add 10?

    ELSE ???????? /* StartDate = '2003/01/01' */

    END

Viewing 5 posts - 1 through 4 (of 4 total)

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