SQL Server Select Where is the LIKE value (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 values.

Values
------
A
B
C
D

Now I want to search the table (Users), where the value of the LIKE column is one of the rows (last name) 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 it’s not possible above, how else can you do it? Some kind of cycle?

I am using SQL Server 2008

+3
source share
2 answers
SELECT * FROM Users,NewTable WHERE vLastName LIKE Values + '%'
+2
source
SELECT * from Users u 
JOIN StringSplitterResult r on r.Values = SUBSTRING( u.vLastName, 1,1)
+2
source

Source: https://habr.com/ru/post/1721773/


All Articles