March 1, 2010 at 1:16 pm
Hello,
Is there a way I can put the below sql in the /Q"" switch below of OSQL....
DECLARE @result int
EXEC master..xp_cmdshell 'D:\TDPCDrive.bat'
IF (@result = 0)
PRINT 'Success'
ELSE
raiserror('Backup Failed.', 16, 1)
OSQL /SST2IMGPIOCRDB01 /E /b /Q"EXEC master..xp_cmdshell 'D:\Cdrive.bat"
Hopefully i am making sense...
Thanks in Advance...
March 1, 2010 at 2:00 pm
You could do it if you use semi colons to separate your statements somethign along the lines of
DECLARE @result int; EXEC master..xp_cmdshell 'D:\TDPCDrive.bat'
I'm not sure on how the IF Statement would work, you may need to play with it a bit.
However, depending on what you're trying to do it seems like there may be an easier way. Can you give us a bit more about what you are trying to accomplish with your backup routine?
-Luke.
March 1, 2010 at 2:06 pm
OK I did a bit of playing and it looks like you'd need to do something like this...
DECLARE @result int; EXEC master..xp_cmdshell 'D:\TDPCDrive.bat'; IF (@result = 0) BEGIN PRINT 'Success' END ELSE BEGIN raiserror('Backup Failed.', 16, 1) END;
March 2, 2010 at 6:47 am
Luke...I dont see what you typed in the second reply...
Thanks...
March 2, 2010 at 7:13 am
Let's try it without the formatting then...
Basically instead of line breaks to end the statements you need to use other ways to accomplish what a line break does, in this case it's a combination of Semicolons and Begin/End statements. Rumor has it in a future version we're going to have to end every statement with a semicolon so it's just a good practice to get into in the meantime...
DECLARE @result int; EXEC master..xp_cmdshell 'D:\TDPCDrive.bat'; IF (@result = 0) BEGIN PRINT 'Success' END ELSE BEGIN raiserror('Backup Failed.', 16, 1) END;
March 3, 2010 at 4:48 am
You could also put your script in a file and use the -i option to OSQL
Viewing 6 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply