Geeks With Blogs

Arthur Zubarev Compudicted

I am hanging recently around a lot in the MS SQL Server Forums where I have a lot of fun. One of the interesting questions that popped up today was about how to execute several operating system commands that span multiple lines.

Besides, even though the job step editor presents you with a text box, this is not the same as writing a batch file. All the editor does it sees the first command statement. What to do? Some people resorted to writing subsequent commands in the next job step, but this sounded unacceptable to me. The primary reason is, the commands become completely detached and thus hard to follow logically. Is there an alternative? Yes.

Well, this turned out to be more a DOS (Command Shell) related question than the SQL Server one!

One should simply type the commands together like

SET MyVar=123 && dtexec foo

Elegant yet simple!

One point to bear in mind, in the example below the second commands executes ONLY if the first succeeded or returned the expected result.

In most cases this is what is needed, for all others you can simply separate the commands with a single & (ampersand).

Posted on Friday, September 24, 2010 3:45 PM | Back to top

Comments on this post: Execute Multiple Operating System (CmdExec) Commands within One Step of SQL Server Agent Job

No comments posted yet.
Your comment:
 (will show your gravatar)

Copyright © Compudicted | Powered by: