Search code examples
sqlsql-serversqlcmd

Stored procedure execution


I have written a stored procedure to be called from sqlcmd (batch file). This is the code - for some reason it is not executing.

@ECHO OFF
SET /P FDate=Enter From Date: 
SET /P TDate=Enter To Date: 
ECHO sqlcmd -E -Q "dbo.SavingsAccountsAllDetail @FDate=N'%Param1%', @TDate=N'%Param2%'" -S OMNIDB-UAT -d HNBG_LOAN_TEST -o C:\SavingsAccountsAllDetailRepo.txt
SET Param1=
SET Param2=

Any thoughts?


Solution

  • Try to add EXEC before procedure's name:

    sqlcmd -E -Q "exec dbo.SavingsAccountsAllDetail @FDate=N'%Param1%', @TDate=N'%Param2%'" -S OMNIDB-UAT -d HNBG_LOAN_TEST -o C:\SavingsAccountsAllDetailRepo.txt
    

    You can also try to passparameters via the /v argument. More datais here

    sqlcmd -E -Q "exec dbo.SavingsAccountsAllDetail @FDate=N'$(Param1)', @TDate=N'$(Param2)'" /v Param1=%Param1% Param2=%Param2%  -S OMNIDB-UAT -d HNBG_LOAN_TEST -o C:\SavingsAccountsAllDetailRepo.txt