将周差异转换为周日期SQL Server

时间:2018-07-05 13:08:55

标签: sql sql-server

如何将所有星期的差异列值转换为每周的开始日期?

样本数据:

Week Diff | Value
1         | 20000
2         | 30000
3         | 40000

预期结果:

Week Diff | Value
6/24/2018 | 20000
6/17/2018 | 30000
6/10/2018 | 40000

我看过类似的帖子,但是我不明白如何根据自己的需要更改解决方案。例如

declare @wk int  = week_diff
select dateadd(week,@wk-1, DATEADD(wk, DATEDIFF(wk,-1,DATEADD(yy, DATEDIFF(yy,0,getdate()), 0)), 0))

请告知。

1 个答案:

答案 0 :(得分:0)

尝试一下:

select
    convert(date,DATEADD(wk, DATEDIFF(wk,0,getdate())-[Week Diff], 0))
from yourtable