Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
sqlpal2007
Posting Yak Master
200 Posts |
Posted - 2007-10-25 : 09:23:10
|
Hello All,I have to get the output of sp_helprotect for each database on a server in temp tables. I have prepared a dynamic sql using cursor to go through each database and exec the sp_helprotect.But I get the following error: @sql print statements are correct.Msg 2812, Level 16, State 62, Line 33Could not find stored procedure 'INSERT INTO #helprotectASPState exec sp_helprotect '.Msg 2812, Level 16, State 62, Line 39Could not find stored procedure 'ALTER Table #helprotectASPState ADD DBName varchar(100) '.Msg 2812, Level 16, State 62, Line 45Could not find stored procedure 'UPDATE #helprotectASPState SET DBName = '@DBName''.Msg 2812, Level 16, State 62, Line 33Here is the query:declare @sql varchar(4000), @DBName varchar(100), @sql1 varchar(1000)declare database_cursor cursorfor select name from master..sysdatabasesorder by namefor read onlyopen database_cursor fetch next from database_cursor into @DBName WHILE @@FETCH_STATUS = 0 BEGIN select @sql = 'CREATE TABLE #helprotect' + @DBName + ' ( ' + 'owner varchar(10), ' + 'object varchar(100), ' + 'grantee varchar(100), ' + 'grantor varchar(100), ' + 'protecttype varchar(100), ' + 'action varchar(100), ' + 'columna varchar(100) )' --print @sql exec (@sql) select @sql = '' select @sql = 'INSERT INTO #helprotect' + @DBName + ' exec sp_helprotect ' --print @sql exec @sql SELECT @sql = '' SELECT @sql = 'ALTER Table #helprotect' + @DBName + ' ADD DBName varchar(100) ' --print @sql exec @sql select @sql = '' select @sql = 'UPDATE #helprotect' + @DBName + ' SET DBName = ' + '''@DBName''' --print @sql EXEC @sql FETCH NEXT FROM database_cursor INTO @DBName endclose database_cursordeallocate database_cursorYour help would be greatly appreciated.Thanks in advace,-P |
|
X002548
Not Just a Number
15586 Posts |
|
sqlpal2007
Posting Yak Master
200 Posts |
Posted - 2007-10-25 : 09:59:15
|
Thanks for your reply Brett.Does that mean I have to have one dynamic sql to resolve this problem?Thanks,-P |
 |
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2007-10-25 : 10:12:52
|
No, you can create all the #temp tables before looping, and doing an insert in the dynamic loop. E 12°55'05.25"N 56°04'39.16" |
 |
|
sqlpal2007
Posting Yak Master
200 Posts |
Posted - 2007-10-25 : 11:20:55
|
I guess I can do that or I can create the tables in the temp database and then drop them.Thanks guys,-P |
 |
|
|
|
|
|
|