日期:2014-05-17 浏览次数:20755 次
declare @s varchar(100)
set @s='''a'',''b'',''c'',''d'',''e'',''f'''
select *
from tb
where CHARINDEX(@s,col1)>0
USE CSDN
GO
CREATE TABLE #temp(col1 VARCHAR(10))
INSERT #temp
SELECT 'b' UNION ALL
SELECT 'c' UNION ALL
SELECT 'd'
--楼主没说你TB表中col1的数据的结构,参考如下:
DECLARE @string VARCHAR(100)
SET @string = 'a,b,c,d,e,f'
SELECT b.string FROM
(SELECT string=CONVERT(XML, '<root><v>'+replace(@string,',','</v><v>')+'</v></root>')) a
OUTER APPLY
(SELECT string = C.v.value('.','NVARCHAR(MAX)') FROM a.string.nodes('/root/v') C(v)) b
WHERE NOT EXISTS
(
SELECT 1 FROM #temp m
WHERE m.col1 = b.string
)
/*
string
a
e
f
*/