Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SQL brings back wrong data

Status
Not open for further replies.

rlusk49

Technical User
Nov 7, 2002
18
CA
With the following sql, I am trying to return data based on 2 criteria, argDirectParent and argSpouseParent. But it is not working. It brings back faulty data based on only one of the criteria. I figured the "And" would do it.

Select * From tblPersons Where Mother = " & Chr(39) & argDirectParent & Chr(39) Or Father = " & Chr(39) & argDirectParent & Chr(39) And Mother = " & Chr(39) & argSpouseParent & Chr(39) Or Father = " & Chr(39) & argSpouseParent & Chr(39)
 
Try adding brackets as below

Select * From tblPersons Where (Mother = " & Chr(39) & argDirectParent & Chr(39) Or Father = " & Chr(39) & argDirectParent & Chr(39)) And (Mother = " & Chr(39) & argSpouseParent & Chr(39) Or Father = " & Chr(39) & argSpouseParent & Chr(39))

cjw
 
Hi there

SonOfEmidec1100 is right, without the brackets your statement is broken up so that if one of the OR statements is correct you'll return values that aren't what you want.

Transcend
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top