Select Column Value based on date

  • HI ,

    I'm looking for some help figuring out how to go about Selecting Column Value based on  todays date.
    I have a columns 1 through 31 and Id like to select that value for today. eg: today is the 03/01/19  based on this date Id like to select value from column 1

    I was think this would be some type of case statement but I cant d it

    Thanks
    Greg

  • Unless you use dynamic SQL you will have to write something like this:
    SELECT CASE DATEPART(day,GETDATE())
        WHEN 1 THEN t.Col1
        WHEN 2 THEN t.Col2
        ...
        WHEN 30 THEN t.Col30
        WHEN 31 THEN t.Col31
       END DateCol
    from myTable t

  • Great !!!  that did the trick 🙂
    Thanks so much

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

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