SELECT ROW_NUMBER() OVER (ORDER BY Name) id, Name
INTO #MpsB
DECLARE @counter INT = 1;
DECLARE @maxCount INT = (SELECT COUNT(*) FROM #MpsB);
WHILE @counter <= @maxCount
BEGIN
select * from #MpsB where id=counter
SET @counter = @counter + 1;
END;
方法2:
declare @id int ;
declare @name varchar(100)='';
DECLARE cursor_name CURSOR FOR
SELECT ID,Name FROM YourTable;
OPEN cursor_name;
FETCH NEXT FROM cursor_name INTO @id,name;
WHILE @@FETCH_STATUS = 0
BEGIN
EXEC YourStoredProcedure @id;
FETCH NEXT FROM cursor_name INTO @id,@name;
END;
CLOSE cursor_name;
DEALLOCATE cursor_name;
网友评论