Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


Pass a parameter to a sql cmd

Posted on 2008-11-18
Medium Priority
Last Modified: 2012-05-05
I am trying to pass a parameter into a sqlcmd something like this. The following is a part of the batch job.

sqlcmd  -S ServerName -d db /U sa /P sa /i E:SQLTest.sql %1 -o E:\test.txt

and have the sqltest.sql is an update statement similiar to this

UPDATE    JobStatus
SET              Status = 'Finished'
where JobName = '%1'

I need the %1 to update to a different value as the batch is run.

Does anyone know how to accomplish?
Question by:earngreen
1 Comment
LVL 29

Accepted Solution

Michael Pfister earned 2000 total points
ID: 22993934

Crate a batch similar to this:

echo UPDATE  JobStatus SET  Status = 'Finished' where JobName = '%1' > SQLTest.sql
sqlcmd  -S ServerName -d db /U sa /P sa /i E:SQLTest.sql %1 -o E:\test.txt

Run it with

Batch Jobname

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When you receive another warning that your shared drive is almost full and you have asked your users to clean out old files again and again, here is a single command that may help. This command will place all the files that have not been used rec…
You may have already been in the need to update a whole folder stucture using a script. Robocopy does it well and even provides a list of non-updated files in a log (if asked to). Generally those files that were locked by a user or a process by the …
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
Enter Foreign and Special Characters Enter characters you can't find on a keyboard using its ASCII code ... and learn how to make a handy reference for yourself using Excel ~ Use these codes in any Windows application! ... whether it is a Micr…
Suggested Courses

579 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question