我在使用SSRS时遇到了一些麻烦,我认为这应该是非常基础的。我已经看到了关于IIF语句和其他语句的一些答案,但并没有完全解决这个问题。
我是SSRS的新手,所以我不确定您可以在使用PLSQL的数据部分中使用哪些代码/语法。
我想要做的就是有一个基于参数是否为null的if语句。我尝试了各种语法,但它一直在抛出错误。有什么建议吗?
类似的东西:
IF (:start_date IS NULL) THEN
SELECT wo.wonum, wo.worktype, wo.description wo_description, wo.targcompdate, wo.assetnum,
s.siteid, s.description s_description,
round((wo.targcompdate - sysdate), 0) DaysTillDue
FROM workorder wo
INNER JOIN site s on wo.siteid = s.siteid
WHERE
(wo.targcompdate - sysdate) >= :Low_Day
and (wo.targcompdate - sysdate) <= :High_Day
and wo.siteid = :site_param
and wo.worktype = :worktype_param;
ELSE
SELECT wo.wonum, wo.worktype, wo.description wo_description, wo.targcompdate, wo.assetnum,
s.siteid, s.description s_description,
round((wo.targcompdate - sysdate), 0) DaysTillDue
FROM workorder wo
INNER JOIN site s on wo.siteid = s.siteid
WHERE
(wo.targcompdate - sysdate) >= :Low_Day
and (wo.targcompdate - sysdate) <= :High_Day
and wo.siteid = :site_param
and wo.worktype = :worktype_param
and targcompdate between :start_date and :end_date;
END;
答案 0 :(得分:1)
你可以使用动态SQL表达式(尽管由于诸如SQL注入之类的考虑因素,这些表达式通常已被弃用),但鉴于两个查询之间的唯一区别是额外的最终条件,我建议而是以下查询:
SELECT wo.wonum, wo.worktype, wo.description wo_description, wo.targcompdate,
wo.assetnum, s.siteid, s.description s_description,
round((wo.targcompdate - sysdate), 0) DaysTillDue
FROM workorder wo
INNER JOIN site s on wo.siteid = s.siteid
WHERE (wo.targcompdate - sysdate) >= :Low_Day
and (wo.targcompdate - sysdate) <= :High_Day
and wo.siteid = :site_param
and wo.worktype = :worktype_param
and (:start_date is NULL or targcompdate between :start_date and :end_date)