有人可以告诉我最后一个WHERE子句的错误吗?
我有以下查询在SQL中正常工作:
with
t1
as
(select ID, state, T, U, R,
row_number() over (partition by ID, U order by T asc) as asc_T,
row_number() over (partition by ID, U order by T desc) as desc_T
from rawdata
where R like ‘%123%’)
select ID,
max(case when desc_T = 1 then state else null end) as state2,
max(case when asc_T = 1 then T else null end) as T_0,
max(case when desc_T = 1 then T else null end) as T_End,
U, R
from t1
group by ID, U, R
order by ID, U
当我将它们插入SSRS时>数据集属性>查询的唯一区别是我在最后一组之前添加了一行:
with
t1
as
(select ID, state, T, U, R,
row_number() over (partition by ID, U order by T asc) as asc_T,
row_number() over (partition by ID, U order by T desc) as desc_T
from rawdata
where R like ‘%123%’)
select ID,
max(case when desc_T = 1 then state else null end) as state2,
max(case when asc_T = 1 then T else null end) as T_0,
max(case when desc_T = 1 then T else null end) as T_End,
U, R
from t1
where T > @StartDate and T < @EndDate
group by ID, U, R
order by ID, U
查询类型是文本。我已经验证了我的数据源。
我创建了6个与我的字段来源相同的字段名称:ID,U,R,T_0,T_End,State2
我的查询参数是@StartDate和@EndDate,其值为[@StartDate]和[@EndDate]
但是,当我运行它时,它会丢失一堆数据并且表格显示出来 例如,似乎状态列只选择了第一个'最大情况时',第二个和第三个'最大情况'数据没有返回,并且我得到空白的T_0和T_End值,其中很多是在SQL中,它们都会被返回。
我尝试在没有最后一个WHERE子句的情况下在SSRS中运行查询,它运行正常。
提前致谢。
答案 0 :(得分:1)
确保@StartDate和@EndDate具有与SSRS变量相同的大小写。在TSQL中,情况被忽略(@startdate与@StartDate相同),但在SSRS中则不然。变量案例必须完全匹配。
答案 1 :(得分:0)
发现问题,需要在CTE部分内移动WHERE子句。 感谢您的帮助@MatBailie