If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

Unanswered: Where with Multiple Or

I need to write a wheres statement with multiple Or conditions. What I have is below and is currently working, but not sure if it is proper syntax or if it is working 'now' and will not pull accurately later on. I need to say

Code:

Select * from db1
Where (itemSold1 Like '%Je%' OR itemSold1 Like '%Me%')
Or (itemSold2 Like '%Je%' OR itemSold2 Like '%Me%')
Or (itemSold3 Like '%Je%' OR itemSold3 Like '%Me%')
Or (itemSold4 Like '%Je%' OR itemSold4 Like '%Me%')
Or (itemSold5 Like '%Je%' OR itemSold15 Like '%Me%')

Last edited by jo15765; 09-17-14 at 10:39.
Reason: better formatted the code

The syntax is correct. The only problem you will face is if you need to put an AND in the logic somewhere. Then you will need to put parentheses around all of your ORs to force the order of operations to consider them as a block.

If one brings so much courage to this world the world has to kill them or break them, so of course it kills them. The world breaks every one and afterward many are strong at the broken places. But those that will not break it kills. It kills the very good and the very gentle and the very brave impartially. If you are none of these you can be sure it will kill you too but there will be no special hurry. Earnest Hemingway, A Farewell To Arms.

its the designers job to translate the customer requirement into an effective design. to me it sounds like you are blaming the customer for not doing the design process correctly in the first place (or you took over someone else's design)

its the designers job to translate the customer requirement into an effective design. to me it sounds like you are blaming the customer for not doing the design process correctly in the first place (or you took over someone else's design)

Not blaming a customer in any way, was just stating why the initial design was set-up the way that it was.

I thought about using a "guard character" like the :: in MCrowley's example just in case one item ended with a 'J' or 'M' and the following item started with an 'e'. For this purpose, the guard character can be any character except for 'e' and does NOT need to be included in the wildcard.

As I'm not convinced that this code isn't a contrived example, I didn't bother with the guard character... Without knowing exactly what SQL will be executed there isn't a way for me to guess what guard character is safe.

-PatP

In theory, theory and practice are identical. In practice, theory and practice are unrelated.