好的,在问这个问题之前我已经对这个话题做了很多研究,但是考虑到我的具体情况。目前我的代码如下所示:
SELECT RTRIM(logtype)+'-'+RTRIM(servicenbr)+'-'+CONVERT(varchar(25), idserv) as CaseNbr, (CASE WHEN tn.TeamText IS NULL THEN 'HELPDESK' WHEN tn.TeamText like '' THEN 'HELPDESK' ELSE tn.TeamText END) as SourceTeam, (tn2.TeamText) as DestinationTeam
FROM teamnames as tn2
LEFT OUTER JOIN caseaudit AS ca
ON tn2.teamID = ca.referteamID2
LEFT OUTER JOIN openstatus As os
ON ca.logno = os.logno
LEFT OUTER JOIN teamnames as tn
ON ca.referteamid1 = tn.teamid
WHERE CONVERT(smalldatetime,ca.dModLast,101) BETWEEN '2012-06-04' AND '2012-06-11'
--NEED TO PUT IF CLAUSE HERE
ORDER BY DestinationTeam
具体来说,我的 IF 子句,或者 CASE WHEN,需要测试看看
WHERE ca.asggrp1 <> ca.asggrp2
AND ca.referteamid1 <> ca.referteamid2 AND tn2.isactive = 1 AND tn2.groupid = 18.
If they are equal, then the ticket should be ignored UNLESS
ca.asggrp1 = 'CLIENT' AND ca.asggrp2 = 'CLIENT'
AND ca.referteamid1 <> ca.referteamid2 AND tn2.isactive = 1 AND tn2.groupid = 18.
编辑:
好吧……让我们试试这个。查询应始终拉取具有以下限制的案例:
WHERE ca.referteamid1 <> ca.referteamid2 AND tn2.isactive = 1 AND tn2.groupid = 18
另外,我想将结果限制为 when ca.asggrp1 <> ca.asggrp2
,除非它们都等于 'CLIENT'
编辑:
再试一次……我失去了我的听众。这是我能给出的关于我正在尝试做的最好的解释。
SELECT RTRIM(logtype)+'-'+RTRIM(servicenbr)+'-'+CONVERT(varchar(25), idserv) as CaseNbr, (CASE WHEN tn.TeamText IS NULL THEN 'HELPDESK' WHEN tn.TeamText like '' THEN 'HELPDESK' ELSE tn.TeamText END) as SourceTeam, (tn2.TeamText) as DestinationTeam
FROM teamnames as tn2
LEFT OUTER JOIN caseaudit AS ca
ON tn2.teamID = ca.referteamID2
LEFT OUTER JOIN openstatus As os
ON ca.logno = os.logno
LEFT OUTER JOIN teamnames as tn
ON ca.referteamid1 = tn.teamid
WHERE CONVERT(smalldatetime,ca.dModLast,101) BETWEEN '2012-06-04' AND '2012-06-11'
AND ca.referteamid1 <> ca.referteamid2 AND tn2.isactive = 1 AND tn2.groupid = 18
----AND (ca.asggrp1 <> ca.asggrp2 UNLESS ca.asggrp1 = 'CLIENT' AND ca.asggrp2 = 'CLIENT')
ORDER BY DestinationTeam