Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL Server Select Where value LIKE(temporary table value)

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

like image 985
jamesmhaley Avatar asked Nov 26 '25 00:11

jamesmhaley


1 Answers

SELECT * FROM Users,NewTable WHERE vLastName LIKE Values + '%'
like image 166
Wael Dalloul Avatar answered Nov 27 '25 15:11

Wael Dalloul



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!