SQL replace date values if date is Saturday or Sunday

前端 未结 1 1216
星月不相逢
星月不相逢 2021-01-26 12:47

(Sorry, I couldn\'t think of a better title)

I have created the following select statement (SQL Server) to work as a view.

SELECT DISTINCT 
       dbo.E         


        
相关标签:
1条回答
  • 2021-01-26 13:43

    If you move your case statement into the join, it should work.

    Change

    dbo.MyTable ON dbo.ECB.Date = dbo.MyTable.CutoffDate
    

    To

    dbo.Mytable ON dbo.ECB.Date = case when datepart(weekday, dbo.CutoffDate) IN (6,7) 
        then dateadd(d, -((datepart(weekday, dbo.CutoffDate) + 1 + @@DATEFIRST) % 7), dbo.CutoffDate) 
        else dbo.CutoffDate 
    end
    

    Hope this helps.

    0 讨论(0)
提交回复
热议问题