Sql 写一个存储过程
update A set bo = 1 where id = 1 or id = 2 or ....
id = 1 ,2,5,6..... 需要修改的 id 数是不固定的
它的存储过程怎样写 ? 求教
以及 exec
[解决办法]
create proc proc_test @ids varchar(2000)
as
set nocount on
update A set bo = 1
where charindex(','+cast(id as varchar)+',',','+@ids+',')>0
go
--执行
declare @ids varchar(2000)
set @ids='1,2,5,6'
exec proc_test @ids
create proc proc_test
@ids varchar(max)
AS
BEGIN
set @ids='update A set bo = 1 where id in ('+@ids+')'
EXEC(@ids)
END
go
--执行
declare @ids varchar(max)
set @ids='1,2,5,6'
exec proc_test @ids