We help IT Professionals succeed at work.
Get Started

Logical ORing SQL LIKES

holyfeld
holyfeld asked
on
571 Views
Last Modified: 2012-05-05
I've been happily using the following select statement to return values from a table:

SELECT DISTINCT AliasValue FROM GAS_Aliases2ThemeItems1 WHERE AliasValue LIKE  '%OPCServer\SmarOleServer%'  ORDER BY AliasValue

Then someone put a record in the table with an AliasValue containing OPCServer\OACServer, and I'm supposed return this record in addition to the ones above. No problem! I'll just "OR" the LIKES into something resembling

SELECT DISTINCT AliasValue FROM GAS_Aliases2ThemeItems1 WHERE AliasValue LIKE '%OPCServer\SmarOleServer%' OR '%OPCServer\OACServer%' ORDER BY AliasValue

But this returns all the distinct values in the table. So what happens if we group the LIKE into

SELECT DISTINCT AliasValue FROM GAS_Aliases2ThemeItems1 WHERE AliasValue LIKE ('%OPCServer\SmarOleServer%' OR '%OPCServer\OACServer%') ORDER BY AliasValue

This return a null recordset.

Each "LIKE" individually returns the values expected.

I'm OBVIOUSLY missing something in the LIKE wildcarding syntax.

What should the Select statement look like?

Don

ps: I've upped the point count so I can reward someone who can EXPLAIN this, not just the what.
Comment
Watch Question
This problem has been solved!
Unlock 1 Answer and 8 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE