Hi Everyone,I have a script that is comprised of three blocks of cursors.Each cursor block operates after the previous one sequentially.I would like to wrap these three blocks in a master cursor, and execute the three blocks for each item in the master cursor.The master cursor consists of all the databases on the server.Each block performs a series of permission granting.The question is...How do i tell the detail block to use the database selected fromthe master cursor??ORWhat do i need to change in the detail block to work with the database that is returned in the master cursor?Here is the master cursor detailFOR SELECT [NAME] FROM sys.databases WHERE NAME NOT IN ('dbawork', 'QuestWorkDatabase', 'msdb', 'model', 'tempdb', 'master') ORDER BY [NAME]OPEN curDatabasesFETCH NEXT FROM curDatabases INTO @dbnameWHILE (@@fetch_status <> -1)BEGIN IF (@@fetch_status <> -2) BEGINOne of the detail cursor blocksDECLARE curTables CURSOR FAST_FORWARD FOR SELECT table_name FROM [INFORMATION_SCHEMA].tables ORDER BY table_nameOPEN curTablesFETCH NEXT FROM curTables INTO @nameWHILE (@@fetch_status <> -1)BEGIN IF (@@fetch_status <> -2) BEGIN SET @sql = N'GRANT SELECT,INSERT,DELETE,UPDATE ON ' + @name + ' TO xxxuser;' PRINT @sql EXEC sp_executesql @sql END FETCH NEXT FROM curTables INTO @nameENDCLOSE curTablesDEALLOCATE curTables
thanks in advance