0

Ok, I have done plenty of research on this topic before asking the question, but to avail considering my specific situation. Currently my code looks like this:

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

Specifically, my IF clause, or CASE WHEN, needs to test to see

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.

EDIT:

Alright... let's try this. The query should always pull cases with the limitation:

WHERE ca.referteamid1 <> ca.referteamid2 AND tn2.isactive = 1 AND tn2.groupid = 18

Also, I want to limit the results to when ca.asggrp1 <> ca.asggrp2, except for when they are both equal to 'CLIENT'

EDIT:

One more try here... I lost my audience. This is the best explanation I can give of what I am trying to do.

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
2
  • What do you mean by "if they are equal"? Commented Jun 12, 2012 at 1:30
  • 1
    If, unless... can you please show sample data and desired results for each case? I know your word problem makes sense to you, but it can be quite difficult for others to work backwards from it... Commented Jun 12, 2012 at 1:31

1 Answer 1

1

I feel like an idiot. I just needed to use a simple OR.

AND (ca.asggrp1 <> ca.asggrp2 OR ca.asggrp1 = 'CLIENT' AND ca.asggrp2 = 'CLIENT')

I guess we all over-complicate things now and again.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.