日期:2014-05-18 浏览次数:20737 次
select * from tblA where id in ('00001','00003','00008')
select * from tblA where id in ('00001,00003,00008')
declare @s1 varchar(1000) set @s1=right(replace(','+@s,',',''' as S union select '''),len(replace(','+@s,',',''' as S union select '''))-12)+'''' exec(@s1)
------解决方案--------------------
替换, 变成','
------解决方案--------------------
--用临时表作为数组 create function f_split(@c varchar(2000),@split varchar(2)) returns @t table(col varchar(20)) as begin while(charindex(@split,@c)<>0) begin insert @t(col) values (substring(@c,1,charindex(@split,@c)-1)) set @c = stuff(@c,1,charindex(@split,@c),'') end insert @t(col) values (@c) return end go select * from dbo.f_split('dfkd,dfdkdf,dfdkf,dffjk',',') drop function f_split col -------------------- dfkd dfdkdf dfdkf dffjk (所影响的行数为 4 行)
------解决方案--------------------
这样不行吗 将,替换成',' 转义失败?
where id in (replace(@id,',',''',''')
------解决方案--------------------
SELECT ''''+REPLACE('1,2,3,5,6',',',''',''')+'''' --结果为 '1','2','3','5','6'
------解决方案--------------------
--select * from tblA where id in ('00001,00003,00008') select * from tblA where charindex(','+ltrim(id)+',',','+'00001,00003,00008'+',')>0