Plsql 使用IF语句SSRS 2005的条件WHERE子句

Plsql 使用IF语句SSRS 2005的条件WHERE子句,plsql,reporting-services,reportingservices-2005,Plsql,Reporting Services,Reportingservices 2005,我在SSR方面遇到了一些问题,我认为这应该是非常基本的。我看到了一些关于IIF声明和其他声明的答案,但没有完全解决这个问题 我是SSRS新手,所以我不确定您可以在使用PLSQL的数据部分使用什么代码/语法 我想要做的就是有一个基于参数是否为null的if语句。我尝试过各种语法,但总是出错。有什么建议吗 比如: IF (:start_date IS NULL) THEN SELECT wo.wonum, wo.worktype, wo.description wo_description, wo

我在SSR方面遇到了一些问题,我认为这应该是非常基本的。我看到了一些关于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; 
如果(:开始日期为空),则
选择wo.wonum、wo.worktype、wo.description wo\U description、wo.targcompdate、wo.assetnum、,
s、 站点ID,s.description s_description,
四舍五入((wo.targcompdate-sysdate),0)天到期
来自工单wo
wo.siteid=s.siteid上的内部联接站点s
哪里
(wo.targcompdate-sysdate)>=:低日
和(wo.targcompdate-sysdate)=:低日
和(wo.targcompdate-sysdate)您可以使用动态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)
选择wo.wonum、wo.worktype、wo.description、wo\u description、wo.targetcompdate、,
wo.assetnum,s.siteid,s.description s_description,
四舍五入((wo.targcompdate-sysdate),0)天到期
来自工单wo
wo.siteid=s.siteid上的内部联接站点s
其中(wo.targcompdate-sysdate)>=:低日
和(wo.targcompdate-sysdate)您可以使用动态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)
选择wo.wonum、wo.worktype、wo.description、wo\u description、wo.targetcompdate、,
wo.assetnum,s.siteid,s.description s_description,
四舍五入((wo.targcompdate-sysdate),0)天到期
来自工单wo
wo.siteid=s.siteid上的内部联接站点s
其中(wo.targcompdate-sysdate)>=:低日

以及(wo.targcompdate-sysdate)last和statement到底是如何工作的?如果:start_date param为NULL,它基本上会绕过吗?请参阅-在括号内,如果任一表达式为true,则整个括号都将被视为true;因此,如果
:start\u date
为空,则无论
targetcompdate
是什么,而如果
:start\u date
有值,则必须检查
targetcompdate
是否在指定范围内。好的,谢谢。在本文中,我没有使用或太多,也没有使用参数,所以一开始有点困惑。不过还是有道理的。再次感谢。最后一句话是怎么说的?如果:start_date param为NULL,它基本上会绕过吗?请参阅-在括号内,如果任一表达式为true,则整个括号都将被视为true;因此,如果
:start\u date
为空,则无论
targetcompdate
是什么,而如果
:start\u date
有值,则必须检查
targetcompdate
是否在指定范围内。好的,谢谢。在本文中,我没有使用或太多,也没有使用参数,所以一开始有点困惑。不过还是有道理的。再次感谢。