CREATE PROC AccountPersonSelPart
@AccountID varchar(6),
@StrSql varchar(400) /*存储传过来的查询语句*/
AS
DECLARE @PersonID int
EXEC ('declare cur cursor for '+@StrSql)
open Cur
fetch first from Cur into @PersonID
while (@@fetch_status = 0)
begin
INSERT INTO AccountPerson(AccountID,PersonID) VALUES (@AccountID,@PersonID)
fetch next from Cur into @PersonID
end
close Cur
deallocate Cur
RETURN
@AccountID varchar(6),
@StrSql varchar(400) /*存储传过来的查询语句*/
AS
DECLARE @PersonID int
EXEC ('declare cur cursor for '+@StrSql)
open Cur
fetch first from Cur into @PersonID
while (@@fetch_status = 0)
begin
INSERT INTO AccountPerson(AccountID,PersonID) VALUES (@AccountID,@PersonID)
fetch next from Cur into @PersonID
end
close Cur
deallocate Cur
RETURN
可检查处:
1.@strsql 的select 语句提取了多个字段2.@strsql 的select 语法错误
@AccountID varchar(6),
@StrSql varchar(400) /*存储传过来的查询语句*/
AS
DECLARE @PersonID int
exec('declare cur cursor LOCAL scroll
for '+@StrSql) /*就是此处有错误,不知该怎么处理*/
open Cur
fetch first from Cur into @PersonID
while (@@fetch_status = 0)
begin
INSERT INTO AccountPerson(AccountID,PersonID) VALUES (@AccountID,@PersonID)
fetch next from Cur into @PersonID
end
close Cur
deallocate Cur
RETURN
EXEC ('declare cur cursor for '+@StrSql)