我有需要修改的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
答案 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