Comments
4 comments
-
Change the following:
select @cmd = 'master..sqlbackup ''-SQL "CONVERT ' + '''''' + @f1 + '''''' + ' to ' + '''''' + @f2 + '''''' + '"' + '''' exec (@cmd)
toselect @cmd = '-SQL "CONVERT ' + '''''' + @f1 + '''''' + ' to ' + '''''' + @f2 + '''''' + '"' + '' exec master..sqlbackup @cmd, @exitcode OUT, @sqlerrorcode OUT
This allows you to retrieve the exit code and sql error codes, and respond accordingly. -
Thanks for looking into my question. Your example gives a syntax error. When I correct the syntax as I think it should be, I get error 870 (No command passed to SQL Backup). Is it possible to pass a variable to sqlbackup as the -SQL parameter? I manipulate the @cmd string to be a syntactically correct sqlbackup -SQL command and I get exitcode error 870 and a list of parameter options or else I've set the string up incorrectly and get a syntax error. This is only when I try to incorporate @exitcode and @sqlerrorcode.
This works:select @cmd = 'master..sqlbackup ''-SQL "CONVERT ' + '''''' + @f1 + '''''' + ' to ' + '''''' + @f2 + '''''' + '"' + '''' exec (@cmd)
I just can't get the exit and error codes with it. -
Hi,
Try this :SET @cmd = '-SQL "CONVERT ''' + @f1 + ''' TO ''' + @f2 + '''"' EXEC MASTER..sqlbackup @cmd, @exitcode OUT, @sqlerrorcode OUT
I hope it helps, -
Matthew,
It works perfectly. A single quote solution! I never even attempted that angle. I kept creating the -SQL parameter with the same syntax that the GUI creates. You can't imagine my frustration quoting quotes, always thinking a few more in the right place would get the string '''just' + ' ' + 'right'''.
Thank you very much.
Add comment
Please sign in to leave a comment.
If I force an error by using a bad path for the source file and run the SP in query analyzer I get an error reported from SQL Backup:
output
NULL
SQL Backup v5.3.0.178
Verifying...
Error 530: File does not exist: (\\filcnc1s08pp001\sqlback01\SoftMedx\Nov_11_2008_SoftMed_FULL.SQB)
SQL Backup exit code: 530
name value
exitcode 530
sqlerrorcode 0
filename001 \\filcnc1s08pp001\sqlback01\SoftMedx\Nov_11_2008_SoftMed_FULL.SQB
If I run the same procedure as a job step it completes reporting success.
Here is the SP: