Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 string compare in select statement

Author  Topic 

rnbguy
Constraint Violating Yak Guru

293 Posts

Posted - 2007-04-19 : 20:18:48
is there a way to have a select statement which compares a value is like ('%a%','%b%','%c%','%d%','%f%','%l%')

so :

select address
from customers
where address like ('%a%','%b%','%c%','%d%','%f%','%l%')

???

jsmith8858
Dr. Cross Join

7423 Posts

Posted - 2007-04-19 : 20:48:09
if you really are checking for a single letter, as in your example, then all you need is:

select address
from customers
where address like '%[abcdfl]%'

if you are looking for patterns of multiple letters, then you must use OR:


select address
from customers
where address like '%abc%' or address like '%def%' or ..... etc ...


- Jeff
http://weblogs.sqlteam.com/JeffS
Go to Top of Page

rnbguy
Constraint Violating Yak Guru

293 Posts

Posted - 2007-04-19 : 21:01:12
damn :(
thanx anyway
Go to Top of Page

LoztInSpace
Aged Yak Warrior

940 Posts

Posted - 2007-04-19 : 21:16:28
Why does it matter if you do it as an OR instead of what you have just written?
Go to Top of Page

rnbguy
Constraint Violating Yak Guru

293 Posts

Posted - 2007-04-19 : 21:25:04
because what we've done is added all those values to another tables
so now its pretty impossible because we'd have to compare address contains a value from another table

sounds bit confusing, did that make sense?
Go to Top of Page

LoztInSpace
Aged Yak Warrior

940 Posts

Posted - 2007-04-20 : 01:20:25
If I understand what you have done you can just join to that other table.

select address
from customers
inner join other_table on
customers.address like other_table.address_bit+'%'

assuming your other table contains

address_bit
-----------
a
b
c
d
Go to Top of Page

rnbguy
Constraint Violating Yak Guru

293 Posts

Posted - 2007-04-20 : 02:56:38
done deal
Go to Top of Page
   

- Advertisement -