title: Pass login name as a variable in a SQL Server script
body: <p>I have the following script that I want the production guys to execute using sqlcmd. I want to pass the name of the APP_POOL_USER as a variable to the script, since they want it that way. Don't ask me why. </p>
  
  <pre><code>CREATE USER [$(APP_POOL_USER)] FOR LOGIN [$(APP_POOL_USER)] 
    WITH DEFAULT_SCHEMA=[schema]
  </code></pre>
  
  <p>I get the following error when I execute the code above</p>
  
  <blockquote>
    <p>Msg 15007, Level 16, State 1, Line 2
        '$(APP_POOL_USER)' is not a valid login or you do not have permission.</p>
  </blockquote>
  
  <p>How can this be done?</p>
  
  <p>EDIT:</p>
  
  <p>This is the batch file to execute it I have so far </p>
  
  <pre><code>@ECHO OFF
  
  SET DB_SERVER_NAME = ".\SQLEXPRESS"
  SET APP_POOL_ACCOUNT = "ExUserAccout"
  
  
  
  
  sqlcmd.exe -E -S "%DB_SERVER_NAME%" -i "SQL_DB.sql" -o SQL_DB.log -v APP_POOL_USER="%APP_POOL_ACCOUNT%" 
  </code></pre>