declare @a varchar(8000) set @a = '1,2,3' update 表1 set name=lk where charindex(id,@a,1) > 0
参数@str,值的形式: '1,2,3,4' update 表1 set name=lk where charindex(','+id+',',','+@str+',')>0
--建立存储过程 create proc upd @id1 varchar(8000) as declare @str varchar(8000) set @str='update 表1 set name=lk where id in('+ @id1+')' exec(@str) go--调用存储过程 exec proc 1,2,3
declare @str varchar(20) set @str='1,2,3' exec ( 'update 表1 set name=''lk'' where id in('+@str')' )
--建立存储过程 create proc upd @id1 varchar(8000) as declare @str varchar(8000) set @str='update 表1 set name=lk where id in('+ @id1+')' exec(@str) go--调用存储过程 exec upd 1,2,3
如果id时int则 declare @a varchar(8000) set @a = '1,2,3' update 表1 set name=lk where charindex(convert(varchar(20),id),@a,1) > 0
--正解 --建立存储过程 create proc upd @id1 varchar(8000) as declare @str varchar(8000) set @str='update 表1 set name=''lk'' where id in('+ @id1+')' exec(@str) go--调用存储过程 exec upd '1,2,3'
declare @i varchar(50),@sql varchar(1000) select @i='1,2,3',@sql='' set @sql='update 表1 set name=lk where id in('+@i+')' exec(@sql)
set @a = '1,2,3'
update 表1 set name=lk where charindex(id,@a,1) > 0
update 表1 set name=lk where charindex(','+id+',',','+@str+',')>0
create proc upd
@id1 varchar(8000)
as
declare @str varchar(8000)
set @str='update 表1 set name=lk where id in('+ @id1+')'
exec(@str)
go--调用存储过程
exec proc 1,2,3
set @str='1,2,3'
exec
(
'update 表1 set name=''lk''
where id in('+@str')'
)
create proc upd
@id1 varchar(8000)
as
declare @str varchar(8000)
set @str='update 表1 set name=lk where id in('+ @id1+')'
exec(@str)
go--调用存储过程
exec upd 1,2,3
declare @a varchar(8000)
set @a = '1,2,3'
update 表1 set name=lk where charindex(convert(varchar(20),id),@a,1) > 0
--建立存储过程
create proc upd
@id1 varchar(8000)
as
declare @str varchar(8000)
set @str='update 表1 set name=''lk'' where id in('+ @id1+')'
exec(@str)
go--调用存储过程
exec upd '1,2,3'
select @i='1,2,3',@sql=''
set @sql='update 表1 set name=lk where id in('+@i+')'
exec(@sql)