Pass a parameter to a sql cmd

earngreen
earngreen used Ask the Experts™
on
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?
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

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

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial