Passing parameter to sql script file (stored procedure) from a batch file


I made use of batch file and script file (which executes SP) For it firstly ,I need to invoke batch file from the code , i need to pass data from code to a batch file and in batch file i need to call a sql script file which executes different stored procedures . (I also need to pass parameters from batch file to script file )

Write the following lines in the code behind file .


Dim process As New System.Diagnostics.Process
Dim startInfo As New ProcessStartInfo(AppDomain.CurrentDomain.BaseDirectory & "bat file name ", "username password systemname Database arguments")
process.StartInfo = startInfo
process.Start()

---------------------------------------------
let the batch file name be abc.bat

SQLCMD -U %1 -P %2 -S %3 -d%4 -i"script file path \test.sql" -v inputDate1=%5 -- >
pause
%1 - username
%2 - password
so on ..
%5 -- arguments in code behind file (input Date1 is varaiable to be passed to test.sql)

---------------------------------------------------
sql file
----------
  
DECLARE @inputDate2 as DATETIME
SET @inputDate2 = '$(inputDate1)'
write all the execute statements here ./
ex :
Exec Procedure_name @inputDate2
-- > @inputDate2 is the input parameter for procedure name


Comments



  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:
    Email: