User input for batch files running a stored procedure

  • I created a stored procedure that asks the user for two variables before it runs, a month and a year. The stored procedure has already been tested and runs fine. I have created a batch file that will run the stored procedure but I dont know how to get the batch file to ask for user input and then submit that input into the stored procedures two variables. Can anybody help me with this?

  • Not sure what you mean by a batch file. Most .BAT files (which is what I think of when I think of a batch file), operate mostly without human intervention, and don't ask for input variables. Or are you talking about something else?

    - Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
    Property of The Thread

    "Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon

  • im trying to create a bat file that will ask for user input for two variables that my stored procedure needs to run. This is what I have so far

    : Run on dev

    @ECHO OFF

    set /p USERMONTH = Enter MONTH FOR RECORDS TO BE DELETED

    set /p USERYEAR = ENTER YEAR FOR RECORDS TO BE DELETED

    osql -Dg1dbdev -SGPATLQQ01 -dGERS EXEC BackupReportingTables @USERMONTH = MONTH @USERYEAR = YEAR

    my bat file is not working however and i have been trying to do research on how to do this all day long. The stored procedure itself works just fine

  • here is the corrected code, i realized my variables had different names

    : Run on dev

    @ECHO OFF

    set /p USERMONTH = Enter MONTH FOR RECORDS TO BE DELETED

    set /p USERYEAR = ENTER YEAR FOR RECORDS TO BE DELETED

    osql -Dg1dbdev -SGPATLQQ01 -dGERS EXEC BackupReportingTables @USERMONTH = USERMONTH @USERYEAR = USERYEAR

  • Hi,

    you need to delimit your parameters with the percent sign.

    Example:

    : Run on dev

    @ECHO OFF

    set /p dbname=Enter dbname

    osql -E -dmaster -Q "EXEC sp_helpdb @dbname = '%dbname%'"

    PAUSE

    Edit: Provided better example

    Best Regards,

    Chris Büttner

Viewing 5 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic. Login to reply