SET DATEFIRST in FUNCTION

前端 未结 4 1055
悲哀的现实
悲哀的现实 2020-12-16 01:37

I want to SET DATEFIRST in my function but it is not allowed.

SET DATEFIRST 1

I can add the code in a SP and call the SP from the function

4条回答
  •  独厮守ぢ
    2020-12-16 02:17

    If you need Monday as firstday follow this code snippet

    declare @MyDate datetime = getdate()
                       select CASE WHEN DATEPART(DW,@MyDate) = 1   
                                THEN 7 
                              WHEN DATEPART(DW,@MyDate) <= 7 
                                THEN DATEPART(DW,@MyDate) - 1                            
                         END 
    

提交回复
热议问题