22,207
社区成员
发帖
与我相关
我的任务
分享
select * from tblA where id in ('00001','00003','00008')
select * from tblA where id in ('00001,00003,00008')
--select * from tblA where id in ('00001,00003,00008')
select * from tblA where charindex(','+ltrim(id)+',',','+'00001,00003,00008'+',')>0
SELECT ''''+REPLACE('1,2,3,5,6',',',''',''')+''''
--结果为
'1','2','3','5','6'
where id in (replace(@id,',',''',''')
--用临时表作为数组
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,',',''',''')
declare @s1 varchar(1000)
declare @s1 varchar(1000)
set @s1=right(replace(','+@s,',',''' as S union select '''),len(replace(','+@s,',',''' as S union select '''))-12)+''''
exec(@s1)
strID = "\'" + strID.Trim().Replace(",", "\',\'") + "\'";
处理下字符串。