开发者

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 开发者_JAVA技巧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


SELECT * FROM Users,NewTable WHERE vLastName LIKE Values + '%'


SELECT * from Users u 
JOIN StringSplitterResult r on r.Values = SUBSTRING( u.vLastName, 1,1)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜