?
Solved

sql "like" logic syntax

Posted on 2010-11-22
4
Medium Priority
?
303 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

Get real performance insights from real users

Key features:
- Total Pages Views and Load times
- Top Pages Viewed and Load Times
- Real Time Site Page Build Performance
- Users’ Browser and Platform Performance
- Geographic User Breakdown
- And more

Question has a verified solution.

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

This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.
Suggested Courses

777 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