|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
||||
|
||||
|
Statement problem
This is selecting the wrong record (i.e archived = 0 but the right employee_id). I want to be able to pick an archived record and with the right employee_id AND OR source_id AND OR employee_id. What am I doing wrong in the statemment, any help would be great!!
SELECT L.employee_id AS AddedBy, IV.visit_id AS VisitID, IVO.outcome_id AS OutcomeID, IVO.future_action AS FutureAction, IVO.comments AS Comments, L.lead_id AS LeadID, IVO.employee_id AS CompletedBy, IV.employee_id AS BookedBy, IVO.date_completed AS DateCompleted, L.source_id FROM tblLeads L INNER JOIN tblInspectionVisit IV ON L.lead_id = IV.lead_id LEFT OUTER JOIN tblInspectionVisitOutcome IVO ON IV.visit_id = IVO.visit_id WHERE (IV.archived = 1) AND (IV.visit_id > 0) AND (L.employee_id = 1) OR (L.source_id = 7) OR (IV.employee_id = 1)
__________________
"When I read about the evils of drinking, I gave up reading."
|
|
#2
|
||||
|
||||
|
ANDs take precedence over ORs
what you have is: Code:
WHERE (
IV.archived = 1
AND IV.visit_id > 0
AND L.employee_id = 1
)
OR (
L.source_id = 7
)
OR (
IV.employee_id = 1
)
rewrite your WHERE clause with the appropriate parentheses and you should be okay |
|
#3
|
||||
|
||||
|
Thanks a lot mate!!
|
![]() |
| Viewing: Dev Shed Forums > Databases > MS SQL Development > Statement problem |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|