关于SQL存储过程使用游标循环的问题
我的需求是:在存储过程里使用游标循环一张表.但是这张表是变量.以下是代码:set@sql='selectinstall'+@tablenamedeclareemploye...
我的需求是:
在存储过程里使用游标循环一张表.但是这张表是变量.以下是代码:
set @sql='select install '+@tablename
declare employee_class cursor for
exec @sql
open employee_class
fetch next from employee_class into @install
while @@fetch_status = 0
begin
fetch next from employee_class into @install
end
close employee_class
deallocate employee_class
return
GO
以上写发提示报错,请问如何实现 展开
在存储过程里使用游标循环一张表.但是这张表是变量.以下是代码:
set @sql='select install '+@tablename
declare employee_class cursor for
exec @sql
open employee_class
fetch next from employee_class into @install
while @@fetch_status = 0
begin
fetch next from employee_class into @install
end
close employee_class
deallocate employee_class
return
GO
以上写发提示报错,请问如何实现 展开
展开全部
SET @SQL='
DECLARE @INSTALL 类型
DECLARE EMPLOYEE_CLASS CURSOR FOR
SELECT INSTALL '+@TABLENAME
SET @SQL=@SQL+'
OPEN EMPLOYEE_CLASS
FETCH NEXT FROM EMPLOYEE_CLASS INTO @INSTALL
WHILE @@FETCH_STATUS = 0
BEGIN
FETCH NEXT FROM EMPLOYEE_CLASS INTO @INSTALL
END
CLOSE EMPLOYEE_CLASS
DEALLOCATE EMPLOYEE_CLASS
RETURN
'
EXEC (@SQL)
DECLARE @INSTALL 类型
DECLARE EMPLOYEE_CLASS CURSOR FOR
SELECT INSTALL '+@TABLENAME
SET @SQL=@SQL+'
OPEN EMPLOYEE_CLASS
FETCH NEXT FROM EMPLOYEE_CLASS INTO @INSTALL
WHILE @@FETCH_STATUS = 0
BEGIN
FETCH NEXT FROM EMPLOYEE_CLASS INTO @INSTALL
END
CLOSE EMPLOYEE_CLASS
DEALLOCATE EMPLOYEE_CLASS
RETURN
'
EXEC (@SQL)
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询