CREATE TABLE #Rtb_temp(
rid int not null identity(1,1),
id VARCHAR(50)
)
declare @id VARCHAR(5000),
@CP int=0,
@maxCP int=0,
@sql nvarchar(max)=''
insert into #Rtb_temp select id from tb
select @maxCP=MAX(rid) from #Rtb_temp
DECLARE MS CURSOR FOR
SELECT rid,id FROM #Rtb_temp
OPEN MS
FETCH NEXT FROM MS INTO @CP,@id
WHILE @@fetch_status=0
BEGIN
IF @CP <@maxCP
BEGIN
SELECT @sql=@sql+@id+','
END else
begin
select @sql=@sql+@id
end
FETCH NEXT FROM MS INTo @CP,@id
END
CLOSE MS
DEALLOCATE MS
exec Procedures @id=@sql
这样写会好点,可以把所有数据显示在一张表里面 。看是否OK、
存储过程不能批量执行,只能用游标一个一个读取你查询出来的id然后执行存储过程