Solved

sql "like" logic syntax

Posted on 2010-11-22
4
298 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
4 Comments
 
LVL 142

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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Performance is the key factor for any successful data integration project, knowing the type of transformation that you’re using is the first step on optimizing the SSIS flow performance, by utilizing the correct transformation or the design alternat…
When you hear the word proxy, you may become apprehensive. This article will help you to understand Proxy and when it is useful. Let's talk Proxy for SQL Server. (Not in terms of Internet access.) Typically, you'll run into this type of problem w…
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

758 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now