-- END CALLOUT B-- BEGIN CALLOUT C-- ADD USER TO DATABASES-------------------------------------------------------------------------------SET NOCOUNT ON SET @CMD= '[MASTER].[DBO].[SP_HELPUSER]'---- GET THE NAME OF ALL DATABASES--DECLARE ALLDATABASES CURSOR FORSELECT NAME FROM [MASTER].[DBO].[SYSDATABASES]

---- REMOVE RECORDS FOR TEMPORARY TABLE IN PREPARATION FOR THE NEXT DATABASE TO BE PROCESSES-- TRUNCATE TABLE #TMPPROTECTEND---- GET NEXT DATABASE TO PROCESS--FETCH NEXT FROM ALLDATABASES INTO @DBEND -- WHILE (@@FETCH_STATUS = 0)---- CLOSE AND DEALLOCATE DATABASE LIST CURSOR--CLOSE ALLDATABASESDEALLOCATE ALLDATABASES---- DROP TEMPORARY TABLE THAT HELD OBJECT PERMISSIONS--DROP TABLE #TMPPROTECT-- END CALLOUT F-- BEGIN CALLOUT G-- PROCESS ALL GENERATED COMMANDS ONE AT A TIME------------------------------------------------------------------------------------- GET ALL THE GENERATED COMMANDS--DECLARE COMMANDS CURSOR FORSELECT * FROM #TMP_LOGIN_RIGHTS

OPEN COMMANDSFETCH NEXT FROM COMMANDS INTO @CMDWHILE (@@FETCH_STATUS = 0)BEGIN---- PRINT COMMAND TO BE PROCESSED--PRINT @CMD---- UNCOMMENT IF YOU WANT THE STORED PROCEDURE TO EXECUTE THE COMMANDS TO ADD THE PERMISSIONS----EXEC (@CMD)---- GET NEXT COMMAND--FETCH NEXT FROM COMMANDS INTO @CMDEND -- WHILE (@@FETCH_STATUS = 0)---- CLOSE AND DEALLOCATE COMMAND CURSOR--CLOSE COMMANDSDEALLOCATE COMMANDS---- DROP TABLE THAT HELD THE GENERATED RIGHTS THAT WHERE GRANTED TO @NEWLOGIN --DROP TABLE #TMP_LOGIN_RIGHTS