Restore Output into variable
HenrikS
Posts: 8 New member
in SQL Backup
We want to write a script that restore a database and run a procedure after the restore.
Then we want to put the output from both the restore statement and the stored procedure in an email and send it to the department who requested the Restore
The output from the SP is no problem. But how to get the output from the restore ?
I only found:https://forum.red-gate.com/discussion/5237/sqlbackup-return-parameter
But this produce only the Number, not the whole Log Outcome.
Is there any way to do this?
Then we want to put the output from both the restore statement and the stored procedure in an email and send it to the department who requested the Restore
The output from the SP is no problem. But how to get the output from the restore ?
I only found:https://forum.red-gate.com/discussion/5237/sqlbackup-return-parameter
But this produce only the Number, not the whole Log Outcome.
Is there any way to do this?
Tagged:
Best Answer
-
petey2 Posts: 88 Silver 3One option, using the SINGLERESULTSET option and a temporary table:IF OBJECT_ID('tempdb..#sqboutput') IS NOT NULLDROP TABLE #sqboutputCREATE TABLE #sqboutput (lines nvarchar(4000))DECLARE @cmd nvarchar(1024)SET @cmd = 'master..sqlbackup ''-sql "RESTORE DATABASE ... WITH ..., SINGLERESULTSET"'''INSERT INTO #sqboutput EXEC sp_executesql @cmdSELECT * FROM #sqboutputDROP TABLE #sqboutputSQL Backup - beyond compression
Answers