Pass a parameter to a sql cmd

Posted on 2008-11-18
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 28

    Accepted Solution


    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

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    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…
    I have published numerous articles here at Experts Exchange that present programs/scripts written in a language called AutoHotkey. Each of those articles has a brief paragraph describing where to download the product and how to install it. I have al…
    Need more eyes on your posted question? Go ahead and follow the quick steps in this video to learn how to Request Attention to your question. *Log into your Experts Exchange account *Find the question you want to Request Attention for *Go to the e…
    how to add IIS SMTP to handle application/Scanner relays into office 365.

    731 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

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now