SQL case when statement

  • Hi below is the scenario which I have currently in my query.

    I need to write this query without any hardoce values , so that it will work til n number of years without modifications.

    please can anybody shed light here...

    Startdate =

    CASE WHEN

    Trandate between '06-04-2013' and '05-04-2014' then '06-04-2013'

    Trandate between '06-04-2012' and '05-04-2013' then '06-04-2012'

    Trandate between '06-04-2011' and '05-04-2012' then '06-04-2011'

    Trandate between '06-04-2010' and '05-04-2011' then '06-04-2010'

    Trandate between '06-04-2009' and '05-04-2010' then '06-04-2009'

    Trandate between '06-04-2008' and '05-04-2019' then '06-04-2008'

    END

    Kind regards,

    Niharika

  • Please do not crosspost. It wastes peoples time and fragments replies.

    Original thread with replies can be found here:

    http://www.sqlservercentral.com/Forums/Topic1537645-391-1.aspx

    Need an answer? No, you need a question
    My blog at https://sqlkover.com.
    MCSE Business Intelligence - Microsoft Data Platform MVP

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

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