title: How to use a SQL Server Parameter Input from Command Line?
body: <p>I'm a SQL Newbie and I'm trying to figure out how to use a Parameter with SQL Thru Command-Line</p>
  
  <p>For my boss/staff I have written Batch Files to run SQL Code for them to export data and the like.  In Access all I have to do is [Paramerter] and it prompts for data to be entered.  </p>
  
  <p>The @State Variable I'd like to be able to be set dynamically.  I'd like the batch file to ask for State and Query use that information.  I have no idea how to do it.</p>
  
  <p>Batch File</p>
  
  <pre><code>sqlcmd -E -S ServerName -i C:\Lead$\SQL\MakeSTPhoeLists.sql
  pause
  </code></pre>
  
  <p>The SQL File</p>
  
  <pre><code>Use LeadsDb
  Go
  
  Declare @State VarChar(2)
  Set @State = 'DE'
  DELETE FROM tblzExportPhone
  
  INSERT INTO tblzExportPhone ( Phone )
  SELECT tblLeads.Phone
  FROM tblLeads
  WHERE tblLeads.ST = @State
  
  Declare @FileName VarChar(100)
  Set @FileName = 'H:\Leads\Storage\STLists\' +  @State +'StatePhoneList.csv'
  
  DECLARE @bcp_cmd4 VARCHAR(400) = ' BCP.EXE LeadsDb..tblzExportPhone out ' 
  SET @bcp_cmd4 = @bcp_cmd4 + 'H:\Leads\SQL\Formats\PhoneTmp.csv' + ' -T -f H:\Leads\SQL\Formats\tblzExportPhone.fmt' 
  SET @bcp_cmd4 = @bcp_cmd4 + ' &amp; Copy /b     H:\Leads\SQL\Formats\ExPhone.csv+H:\Leads\SQL\Formats\PhoneTmp.csv ' + @FileName + ' /y'
  Set @bcp_cmd4 = @bcp_cmd4 + ' &amp; Del H:\Leads\SQL\Formats\PhoneTmp.csv'
  </code></pre>
  
  <p>Thank You.</p>