Click to See Complete Forum and Search --> : Non-short-circuit or


TalentGMU
04-03-2007, 09:46 PM
I am stuck in a bit of a problem. I am using the statement:
select count(refs_id) from refs, people, jobs where refs.cid=people.cid and refs.reference=jobs.reference and (jobaccountmanager='Someone' or candidrecruiter='Someone');

now my problem is if an interview(refs) is made by 'Someone' who is the jobaccountmanager AND the candidrecruiter then the above statement returns 1 where I want it to return 2. Basically as soon as jobaccountmanager='Someone' it short circuits and doesn't check the candidrecruiter. I need to find a way for count to return 2 instead of one. Is there a non-short circuit method for or in sql? Plus I know this could be solved if I would just split the select statement into two statements and then add but to make a long story short that is not an option. Help would be GREATLY appreciated.

mattyblah
04-04-2007, 02:48 PM
select Sum(Case When jobaccountmanager = 'Someone' AND candidrecruiter = 'Someone' Then 2 When jobaccountmanager = 'Someone' Then 1 When candidrecruiter = 'Someone' Then 1 Else 0 End) from refs, people, jobs where refs.cid=people.cid and refs.reference=jobs.reference and (jobaccountmanager='Someone' or candidrecruiter='Someone')

That might work. The reason your other query isn't returning what you want is because you are counting the records. Or short circuits because it has found a true statement, and having it not short circuit would not return a higher count, it would just take longer.