TSQL Calculate week number of the month

前端 未结 5 738
逝去的感伤
逝去的感伤 2020-12-06 13:20

I want to calculate the week number of the month,I want to calculate the week number whether its odd or even week how can I get this in TSQL ? Thanks all!

5条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-06 13:45

    Try this:

    SELECT (DATEPART(d, '02/07/2011')/7)%2 AS WeekNo, --Replace your date column in place of '02/07/2011'
           CASE (DATEPART(d, '02/07/2011')/7)%2 
                    WHEN 1 THEN 'Odd' 
                    ELSE 'Even'
                 END AS WeekType
    

提交回复
热议问题