动态SQL及游标请教,在线等。。。
下面是我的存储过程:
BEGIN
DECLARE @ID_CURSOR CURSOR FOR
EXEC( 'SELECT C_ORGID FROM '+ @databasename+ '. ' +@databaseAdmimistrator+ '. ' + 'ORG_INFO WHERE C_ORGID NOT IN(SELECT FVORGID FROM ORGANIZATION) ');
END
想用动态SQL生成结果集放入游标。提示说FOR附近有语法错误。请问应该如何修改?
谢谢!
------解决方案--------------------exec( 'declare cur cursor for select c_orgid fro...............
------解决方案--------------------你可以把内容先放到临时表里如:
EXEC( 'SELECT C_ORGID into #T FROM '+ @databasename+ '. ' +@databaseAdmimistrator+ '. ' + 'ORG_INFO WHERE C_ORGID NOT IN(SELECT FVORGID FROM ORGANIZATION) ')
BEGIN
DECLARE @ID_CURSOR CURSOR FOR select * from #T
END