Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pass parameter value to sql file from batch file using batch command

I have a sql file update_qde.sql which contains the following code

UPDATE profile_const
set parameter_value = '04_2015'
where profile_name = 'MIDAS_MTH_ALL_Panels'
and parameter_name = 'PERIODS_TO';
commit;

quit;

I have another batch file test.bat

I want to pass the parameter_value as a variable from a batch file using batch command.

Could you please show me any way to do this?

like image 562
Azizul Hassan Arif Avatar asked Sep 10 '25 20:09

Azizul Hassan Arif


1 Answers

Use SQLCMD variables, so change test.bat to call SQLCMD rather than ISQL

@echo off
sqlcmd -E -S myserver -i update_qde.sql -v PARM1=2015-01-01

Change the SQL to use the $() notation

UPDATE profile_const
SET parameter_value = '$(PARM1)'
WHERE profile_name = 'MIDAS_MTH_ALL_Panels'
AND parameter_name = 'PERIODS_TO';
COMMIT;
like image 163
greg Avatar answered Sep 13 '25 10:09

greg