I'm trying to implement a sp_MSforeachsp howvever when I call sp_MSforeach_worker
I get the following error can you please explain this problem to me so I can over come the issue.
Msg 16958, Level 16, State 3, Procedure sp_MSforeach_worker, Line 31
Could not complete cursor operation because the set options have changed since the cursor was declared.
Msg 16958, Level 16, State 3, Procedure sp_MSforeach_worker, Line 32
Could not complete cursor operation because the set options have changed since the cursor was declared.
Msg 16917, Level 16, State 1, Procedure sp_MSforeach_worker, Line 153
Cursor is not open.
here is the stored procedure:
Alter PROCEDURE [dbo].[sp_MSforeachsp]
@.command1 nvarchar(2000)
, @.replacechar nchar(1) = N'?'
, @.command2 nvarchar(2000) = null
, @.command3 nvarchar(2000) = null
, @.whereand nvarchar(2000) = null
, @.precommand nvarchar(2000) = null
, @.postcommand nvarchar(2000) = null
AS
/* This procedure belongs in the "master" database so it is acessible to all databases */
/* This proc returns one or more rows for each stored procedure */
/* @.precommand and @.postcommand may be used to force a single result set via a temp table. */
declare @.retval int
if (@.precommand is not null) EXECUTE(@.precommand)
/* Create the select */
EXECUTE(N'declare hCForEachTable cursor global for
SELECT QUOTENAME(SPECIFIC_SCHEMA)+''.''+QUOTENAME(ROUTINE_NAME)
FROM INFORMATION_SCHEMA.ROUTINES
WHERE ROUTINE_TYPE = ''PROCEDURE''
AND OBJECTPROPERTY(OBJECT_ID(QUOTENAME(SPECIFIC_SCHEMA)+''.''+QUOTENAME(ROUTINE_NAME)), ''IsMSShipped'') = 0 '
+ @.whereand)
select @.retval = @.@.error
if (@.retval = 0)
EXECUTE @.retval = [dbo].sp_MSforeach_worker @.command1, @.replacechar, @.command2, @.command3, 0
if (@.retval = 0 and @.postcommand is not null)
EXECUTE(@.postcommand)
RETURN @.retval
GO
example useage:
EXEC sp_MSforeachsp @.command1="PRINT '?' GRANT EXECUTE ON ? TO [superuser]"
GO
Does anyone have a solution to this problem? Please help......
No comments:
Post a Comment