Solved

sql "like" logic syntax

Posted on 2010-11-22
4
302 Views
Last Modified: 2012-05-10
this is some inherited code we have.


SELECT * from data where  (datafield like 'ROUTE|CUSTOMERLOCATION')

doesnt seem to work..  i think they were trying to say   if data is like route OR like customerlocation

select * from data where (datafield like 'ROUTE') or (datafield like 'CUSTOMERLOCATON')

produces the data we are looking for.

Is there a   '|' operator for a like statement?





0
Comment
Question by:CASorter
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 500 total points
ID: 34188875
no.

you have to do:
SELECT * from data 
where  datafield like 'ROUTE'
 OR datafield LIKE 'CUSTOMERLOCATION'

Open in new window

with eventually some % around ...

however, you might get that "list" in a single variable?
then, you need to go to this article:
http://www.experts-exchange.com/A_1536.html
[code]
SELECT * from data 
where datafield in ( select value from dbo.ParmsToList( 'ROUTECUSTOMERLOCATION', '|' ) )

Open in new window

possible a small change if it has to be a LIKE indeed ...





0
 
LVL 18

Expert Comment

by:lludden
ID: 34188962
You don't normally use LIKE unless you have wildcards.  

SELECT * from data
where  datafield IN ('ROUTE','CUSTOMERLOCATION')

0
 
LVL 10

Expert Comment

by:thefritterfatboy
ID: 34189210
@lludden - Actually, older versions of MS SQL Server require the LIKE operator for all operations on TEXT fields, whether you want an exact match or not.

In response to the original post, LIKE does not have an OR operator built in.

(Full text searching is a whole different matter, though. SQL Full Text Search does allow for OR operations)
0
 

Author Closing Comment

by:CASorter
ID: 34189665
thanks,    just wanted to make sure i wasnt missing something.
0

Featured Post

Transaction Monitoring Vs. Real User Monitoring

Synthetic Transaction Monitoring Vs. Real User Monitoring: When To Use Each Approach? In this article, we will discuss two major monitoring approaches: Synthetic Transaction and Real User Monitoring.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
In this article we will learn how to fix  “Cannot install SQL Server 2014 Service Pack 2: Unable to install windows installer msi file” error ?
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question