Re: Why will this "or" staement not work in VB/SQL ADO



matthewwhaley@xxxxxxxxx wrote:
How do you use the "like / OR" statement in ADO?

"ADO"?
Oh! you mean "in SQL"!

When I use one
criteria (line 4), it runs fine



sqlstring = "select BusinessName, BusinessID " _
& "from mars.dbo.mroActiveRollups " _
& "where BusinessDate = '4/30/2007' " _
& "AND businessline like '%WB_TREAS' or '%WB_CMG' " _
& "AND rollupID= 2 " _
& "ORDER BY businessline "

Because that's not the way they work. "Like" has nothing to do with this
issue.
Logical operators (in most languages, not just SQL) are used to separate
logical expressions. A logical expression is an expression that evaluates to
true or false. Here are some examples of logical expressions:

true
false
x=y

When a logical operator is used, you must have two logical expressions:
<this expression evaluates to true> or <this espression evaluates to true>

So lets look at the way you tried to use it:
businessline like '%WB_TREAS' or '%WB_CMG'

Let's use parentheses to highlight the expressions:
(businessline like '%WB_TREAS') or ('%WB_CMG')

So the first espression is definitely a logical expression: it evaluates to
either true or false. The second expression does not qualify as a logical
expression. What you have to do (and what you would have to do in most
languages) is make the second expression logical:
(businessline like '%WB_TREAS') or (businessline like '%WB_CMG')

This is now a single logical expression formed by using a logical operator
to combine two logical expressions.

Also, in order to avoid unexpected results, you should use parentheses to
nest this expression (I will remove the parentheses I put in earlier - they
won't hurt anything but they are not needed either):
(businessline like '%WB_TREAS' or businessline like '%WB_CMG')

--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"


.