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 derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Logic problem 1

Status
Not open for further replies.

sparkbyte

Technical User
Joined
Sep 20, 2002
Messages
879
Location
US
I am having a problem figuring the AND/OR logic in this query.

This is partly to learn the boolean logic better and to create a query to clean up the tracking Table.


Code:
Select 
	Tracking_ID, EmployeeID, MachineName, BoxNumber, FileNumber, TrackingDate, Reship, BoxNumberOriginal
from tblTrackingTable
Where
	BoxNumber = '' OR BoxNumber Is Null
AND
	FileNumber = '' OR FileNumber Is Null
AND
	TrackingDate = '' OR TrackingDate Is Null



Sample output.
Code:
34	NULL	NULL	1Z1A1230355615215	.BOX.END.	NULL	NULL	NULL
35	NULL	NULL	1Z1A123R0355615215	.BOX.END.	NULL	NULL	NULL
36	NULL	NULL	1Z1A1230355615215	.BOX.END.	NULL	NULL	NULL

I was trying to get the script to output all rows where
BoxNumber, FileNumber, TrackingDate are either empty or null.

As seen in the output the FileNumber and BoxNumber are not empty or Null.

Where have I gone wronge in the Where clause?

Thanks

John Fuhrman
 
I have a rule for where clauses that I think EVERYONE should adopt. Here's the rule...

If you mix and's and or's in a where clause, ALWAYS use parenthesis. No exceptions.

If you follow this rule too, it will make things a lot easier for you.

Code:
Where
    [!]([/!]BoxNumber = '' OR BoxNumber Is Null[!])[/!]
AND
    [!]([/!]FileNumber = '' OR FileNumber Is Null[!])[/!]
AND
    [!]([/!]TrackingDate = '' OR TrackingDate Is Null[!])[/!]


-George

"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom
 
I agree with George.

U also also read about operator precedence.
 
Thanks guys, George that did it.

vikramshah1978, I will see what I can find on order precedence.

Thanks

John Fuhrman
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top