views:

128

answers:

2

Hi guys, bear with me, this may be a long one.

Thanks in advance for the help.

I have a function in SQL server 2008 that takes a string: 'A,B,C,D' and splits it and creates a table of the values.

Values
------
A
B
C
D

I now want to search a table (Users) Where a column value is LIKE one of the rows (surname) in the above table.

This is what I would like to do:

SELECT * FROM Users WHERE vLastName LIKE 'A%'
SELECT * FROM Users WHERE vLastName LIKE 'B%'
SELECT * FROM Users WHERE vLastName LIKE 'C%'
SELECT * FROM Users WHERE vLastName LIKE 'D%'

If the above is not possible, how else would you do it? Some kind of loop?

I'm using SQL Server 2008

Any help is appreciated. Thanks again.

+2  A: 
SELECT * from Users u 
JOIN StringSplitterResult r on r.Values = SUBSTRING( u.vLastName, 1,1)
Mark Dickinson
+1  A: 
SELECT * FROM Users,NewTable WHERE vLastName LIKE Values + '%'
Wael Dalloul
Both responses work like a treat, but went with this one.
sparkyfied