わかりました、質問をする前に、このトピックについて十分な調査を行いましたが、私の特定の状況を考慮してください。現在、私のコードは次のようになっています。
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
ca.asggrp1 <> ca.asggrp2
また、両方が「CLIENT」に等しい場合を除いて、結果を when に制限したい
編集:
ここでもう一度試してみてください... 聴衆を失いました。これは、私がやろうとしていることについて私ができる最善の説明です。
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