我正在寻找一种方法,如果用户选择
@startdate = '12-01-2015'
then
@enddate = @startdate + 1 Week
这是我的参数,但请注意我的报告是一个矩阵,每周使用一个数据样本,所以参数需要自动选择 它从所有选定的开始日期结束
即
开始于('12 -01-2015','19 -01-2015')
然后在('18 -01-2015','26 -01-2015')
结束这是我用于我的startdate参数
的内容select distinct
CAST(startdate AS DATE) as Startdate
FROM [Calendar]
where DatePart(YEAR,startdate) >= 2014
order by 1 asc
答案 0 :(得分:0)
使用DATEADD
@startdate = '12-01-2015'
then
@enddate = DATEADD(wk, 1, @startdate)
或者如果startdate变量有DATE/DATETIME
类型
@startdate = '12-01-2015'
then
@enddate = @startdate + 7; -- Implicit cast add 7 days
编辑:
select distinct
CAST(startdate AS DATE) as Startdate,
DATEADD(wk, 1, CAST(startdate AS DATE)) as EndDate
FROM [Calendar]
where DatePart(YEAR,startdate) >= 2014
order by 1 asc