[英]my query works in SQL but not in SSRS
有人可以告訴我我上一個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中運行查詢,並且它工作得很好。
提前致謝。
確保@StartDate和@EndDate具有與SSRS變量相同的大小寫。 在TSQL中,將忽略(@startdate與@StartDate相同),但在SSRS中則不會。 變量大小寫必須完全匹配。
發現問題后,需要在CTE部分中移動WHERE子句。 謝謝您的幫助@MatBailie
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.