By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,265 Members | 1,333 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,265 IT Pros & Developers. It's quick & easy.

MSSQL Query

P: 3
Hi I need some help please

I have several custom fields in a table and want to retrieve the records that match maybe two or three or four of these customised fields.

I have written the query as follows:
SELECT T0.[ItemCode], T0.[ItemName], T0.[U_Brand], T0.[U_BrandOwn], T0.[U_Product], T0.[U_Olfactive1], T0.[U_Olfactive2], T0.[U_Olfactive3], T0.[U_Desc1], T0.[U_Desc2]

FROM OITM T0
WHERE T0.[U_Brand] = $[OQUT.U_Brand] or T0.[U_BrandOwn] = $[OQUT.U_BrandOwn] or T0.[U_Product] = $[OQUT.U_Product] or T0.[U_Olfactive1] = $[OQUT.U_Olfactive1] or T0.[U_Olfactive2] = $[OQUT.U_Olfactive2] or T0.[U_Olfactive3] = $[OQUT.U_Olfactive3]

This returns all items where U_Brand is amber also all records where U_Olifactive1 = Fruity, what I want is only the records that match Amber and are Fruity. The or statement is cusing the problem, if I use the and statement then I must select something from each customised field.

Can anyone help me please
Sep 9 '08 #1
Share this Question
Share on Google+
4 Replies


ck9663
Expert 2.5K+
P: 2,878
Do you want to include if all the other conditions are true?

Try using parenthesis to group your conditions...

-- CK
Sep 9 '08 #2

P: 3
Hi

I want to include all records that match the two, three, or four entries that I make in the selection regardless of the values of any of the other fields. The combination of selected fields may well be different every time the product file is searched.

Thank you for Interest
Sep 10 '08 #3

ck9663
Expert 2.5K+
P: 2,878
This:
Expand|Select|Wrap|Line Numbers
  1. WHERE (T0.[U_Brand] = $[OQUT.U_Brand] or T0.[U_Olfactive1] = $[OQUT.U_Olfactive1]) and
  2. T0.[U_BrandOwn] = $[OQUT.U_BrandOwn] and T0.[U_Product] = $[OQUT.U_Product] and 
  3.  T0.[U_Olfactive2] = $[OQUT.U_Olfactive2] and T0.[U_Olfactive3] = $[OQUT.U_Olfactive3]
will return if U_Brand = OQUT.U_Brand or U_Olfactive1 = OQUT.U_Olfactive1...so if one of this condition is true, the whole condition is true...the rest, however, must be true in order to be the entire condition be true...

Good luck

-- CK
Sep 10 '08 #4

P: 3
Thanks very much for your help, most appreciative.
Sep 11 '08 #5

Post your reply

Sign in to post your reply or Sign up for a free account.