Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

sql "like" logic syntax

Posted on 2010-11-22
4
Medium Priority
?
307 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 2000 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 Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
Ready to get certified? Check out some courses that help you prepare for third-party exams.
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.

618 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