title: Passing parameters to stored procedure using a SQLCMD batch file
body: <p>I am attempting to pass some parameters to a SQL Server stored procedure using a <code>.bat</code> file but I keep getting an incorrect syntax error.</p>
  
  <pre><code>CREATE PROCEDURE sp_TEST 
      (@Username  VARCHAR(20))
  WITH ENCRYPTION
  AS
  BEGIN
      SET NOCOUNT ON
  
      DECLARE @USERID INT
  
      SET @USERID = (SELECT flduserid FROM BPOCORE..tblusers WHERE fldusername = @Username)
  
      UPDATE tbluserdetails 
      SET fldloggedon = 'No' 
      WHERE flduserid = @USERID
  END
  </code></pre>
  
  <p>Here is the batch file:</p>
  
  <pre><code>@ECHO OFF
  NEW BATCH
  
  ECHO. 
  ECHO Welcome - enter details
  ECHO. 
  
  :Login
  ECHO Type in the SQL Server and Login Details as noted below:
          ECHO SQLInstance:
          SET /P SQLInstance= 
          ECHO.
          ECHO DatabaseName
          SET /P DatabaseName=
          ECHO.
          ECHO BPOUserName:
          SET /P BPOUserName=
          ECHO.
          ECHO BPOPassword:
          SET /P BPOPassword=
          ECHO.
          ECHO enter_username
                  set /v test1 =
          ECHO.
  
  sqlcmd -S %SQLInstance% -d %DatabaseName% -l0 -U %BPOUserName% -P %BPOPassword%  -i c:\sp_TEST.sql -v test1
  ECHO.
  PAUSE&amp;EXIT
  </code></pre>
  
  <p>I keep getting this error:</p>
  
  <blockquote>
    <p>ERROR - Syntax of the command is incorrect</p>
  </blockquote>
  
  <p>I don't understand why it is failing and reading the documentation is not helping for this specific issue.</p>