0

test.bat

SQLCMD -s SQL-SL_SQL01 -E -I “C:\Users\sqladmin\test.sql” -v p = "%1"

test.sql

EXEC xp_instance_regwrite N'HKEY_LOCAL_MACHINE' , N'SoftwareMicrosoftMSSQLServerMSSQLServer' , N'DefaultData' , REG_SZ , N’${p}’ GO

In cmd prompt, passing this : test.bat f:\sql

but getting a error like this,

sqlcmd: ':sql', invalid argument

jeb
  • 78,592
  • 17
  • 171
  • 225
  • 2
    Scripting variables: https://learn.microsoft.com/en-us/sql/ssms/scripting/sqlcmd-use-with-scripting-variables?WT.mc_id=DP-MVP-5001259&view=sql-server-ver15 – Martin Cairney Feb 02 '21 at 06:04
  • 1
    Does this answer your question? [How to pass in parameters to a SQL Server script called with sqlcmd?](https://stackoverflow.com/questions/3814302/how-to-pass-in-parameters-to-a-sql-server-script-called-with-sqlcmd) – astentx Feb 02 '21 at 06:21
  • Do not use “smart quotes”. Use the regular style quotes like you have on the "argument". – Squashman Feb 02 '21 at 14:46

0 Answers0