help with formating OSQL

  • 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...

  • 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.

    To help us help you read this[/url]For better help with performance problems please read this[/url]

  • 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;

    To help us help you read this[/url]For better help with performance problems please read this[/url]

  • Luke...I dont see what you typed in the second reply...

    Thanks...

  • 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;

    To help us help you read this[/url]For better help with performance problems please read this[/url]

  • 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