【发布时间】:2015-12-05 20:18:05
【问题描述】:
Table : incident
----------------
incident_id usr_id item_id Inc_Date
10059926 191 61006 8-22-2015
10054444 222 3232 6-7-2015
Table: act_reg
--------------
act_reg_id act_type_id incident_id usr_id act_type_sc
454244 1 10059926 191 ASSIGN
471938 115 10059926 191 TRAVEL TIME
473379 40 10059926 191 FOLLOW UP
477652 115 10059926 191 TRAVEL TIME
489091 504 10059926 191 ADD_ATTCHMNTS
477653 504 10054444 222 ADD_ATTCHMNTS
参数:@attach (value=1, Label=Yes & Value=0, Label=No)
Result (While I am selecting 'Yes' in dropdown)
----------------------------------------------
incident_id usr_id item_id
10059926 191 61006
10054444 222 3232
我的查询:
SELECT incident.incident_id,incident.usr_id,incident.item_id
FROM incident
where exists (select * from act_reg
where incident.incident_id = act_reg.incident_id
and act_reg.act_type_sc (case when @attach=1 and act_reg.act_type_sc='ADD_ATTCHMNTS' then NULL else act_reg.act_type_sc end )
)
请帮帮我。
【问题讨论】:
-
有什么问题?你有错误吗?您是否缺少 act_reg.act_type_sc 和 (case 之间的 = ?
-
@HannoverFist : 改变添加 = 我也没有得到准确的结果。
-
选择
No时的预期结果集? -
我认为您的问题与 NULL 有关。您的 WHERE 子句将始终获取所有记录,因为 act_type_sc 将始终等于 NULL。如果您想在 @attach = 0 时排除 ADD_ATTCHMNTS,请尝试使用
AND (reg.act_type_sc <> 'ADD_ATTCHMNTS' OR @attach = 1)而不是当前的 AND 行。 -
@BhupeshC : 当我选择“否”时,我需要获取没有任何附件信息的结果数据
标签: sql sql-server-2008 reporting-services ssrs-2008 ssrs-2008-r2