如果是PostgreSql中的条件

时间:2015-06-11 06:38:56

标签: postgresql reporting-services ssrs-2008 postgresql-9.2

我有需要修改的Query,就像我传递zone = All然后它应该显示所有其他条件的记录。我必须在SSRS报告中使用此查询,它在这种情况下工作。

select distinct zone, wardno,deptname, 
       cybertec_view_requests.statusname, 
       categoryname,opendate,probdesc 
from cybertec_view_requests
left join cybertec_view_requests_comments on 
cybertec_view_requests_comments.reqid = cybertec_view_requests.id_
where zone= ? and  deptname=? and
opendate between  ? and  ?  and categoryname=?
  group by zone,wardno,deptname, cybertec_view_requests.statusname,
           categoryname,opendate,probdesc
  order by zone,wardno,deptname

1 个答案:

答案 0 :(得分:2)

试试这个

    Hear @zone is your variable to pass in the Query 

    SELECT DISTINCT zone, wardno,deptname, cybertec_view_requests.statusname, categoryname,opendate,probdesc 
    FROM            cybertec_view_requests
    LEFT JOIN       cybertec_view_requests_comments ON cybertec_view_requests_comments.reqid = cybertec_view_requests.id_
    WHERE           zone= CASE WHEN @zone = 'ALL' THEN zone ELSE @zone END and  deptname=? and
                    opendate between  ? and  ?  and categoryname=?
    GROUP BY        zone,wardno,deptname, cybertec_view_requests.statusname,
                    categoryname,opendate,probdesc
    ORDER BY        zone,wardno,deptname