我需要能够在报表生成器中编写报表,并能够选择两年并行比较。
我目前的查询设置显示参数中定义的年份:
DECLARE @ YR_CDE VARCHAR(4) = '2016'
**Select/From statement here**
WHERE YR_CDE = @YR_CDE
但是当我将查询抛入Report Builder时,这并不允许我选择多年。有谁知道我怎么解决这个问题?
答案 0 :(得分:0)
DECLARE @yr1 VARCHAR(4) = '2016',
@yr2 VARCHAR(4) = '2017'
SELECT <your-fields>
FROM <your-table>
WHERE yr_cde = @yr1
OR yr_cde = @yr2
如果您尝试执行一系列年限,则可以使用以下方法:
DECLARE @yr1 VARCHAR(4) = '2016',
@yr2 VARCHAR(4) = '2018'
SELECT <your-fields>
FROM <your-table>
WHERE yr_cde BETWEEN @yr1 AND @yr2
答案 1 :(得分:0)
您可以在where子句中使用IN,如下所示:
Where YR_CDE in (@YR_CDE1, @YR_CDE2)