MS SQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsDatabasesMS SQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old March 9th, 2004, 06:01 AM
dast's Avatar
dast dast is offline
web muppet
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2004
Location: blackpool, uk
Posts: 47 dast User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 6 h 19 m 29 sec
Reputation Power: 5
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."

Reply With Quote
  #2  
Old March 9th, 2004, 12:45 PM
r937's Avatar
r937 r937 is offline
SQL Consultant
Click here for more information.
 
Join Date: Feb 2003
Location: Toronto Canada
Posts: 17,919 r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level) 
Time spent in forums: 1 Month 4 Weeks 12 h 51 m 39 sec
Reputation Power: 1018
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
__________________
r937.com | rudy.ca

Reply With Quote
  #3  
Old March 10th, 2004, 04:11 AM
dast's Avatar
dast dast is offline
web muppet
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2004
Location: blackpool, uk
Posts: 47 dast User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 6 h 19 m 29 sec
Reputation Power: 5
Thanks a lot mate!!

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesMS SQL Development > Statement problem


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway
Stay green...Green IT