[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 309
  • Last Modified:

sql "like" logic syntax

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
CASorter
Asked:
CASorter
1 Solution
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
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
 
lluddenCommented:
You don't normally use LIKE unless you have wildcards.  

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

0
 
thefritterfatboyCommented:
@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
 
CASorterAuthor Commented:
thanks,    just wanted to make sure i wasnt missing something.
0

Featured Post

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now