Re: Why will this "or" staement not work in VB/SQL ADO
- From: "Bob Barrows [MVP]" <reb01501@xxxxxxxxxxxxxxx>
- Date: Thu, 3 May 2007 20:39:40 -0400
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"
.
- Follow-Ups:
- Re: Why will this "or" staement not work in VB/SQL ADO
- From: matthewwhaley
- Re: Why will this "or" staement not work in VB/SQL ADO
- References:
- Why will this "or" staement not work in VB/SQL ADO
- From: matthewwhaley
- Why will this "or" staement not work in VB/SQL ADO
- Prev by Date: Why will this "or" staement not work in VB/SQL ADO
- Next by Date: Re: Serbian (Bosnia and Herzegovina)
- Previous by thread: Why will this "or" staement not work in VB/SQL ADO
- Next by thread: Re: Why will this "or" staement not work in VB/SQL ADO
- Index(es):