title: Conditional logic in PostDeployment.sql script using SQLCMD
body: <p>I am using a SQL 2008 database project (in visual studio) to manage the schema and initial test data for my project. The atabase project uses a post deployment which includes a number of other scripts using SQLCMD's ":r " syntax.</p>
  
  <p>I would like to be able to conditionally include certain files based on a SQLCMD variable. This will allow me to run the project several times with our nightly build to setup various version of the database with different configurations of the data (for a multi-tenant system).</p>
  
  <p>I have tried the following:</p>
  
  <pre><code>IF ('$(ConfigSetting)' = 'Configuration1')
    BEGIN
      print 'inserting specific configuration' 
  :r .\Configuration1\Data.sql
    END
  ELSE
    BEGIN
      print 'inserting generic data' 
  :r .\GenericConfiguration\Data.sql
    END
  </code></pre>
  
  <p>But I get a compilation error: 
  <strong>SQL01260: A fatal parser error occurred: Script.PostDeployment.sql</strong></p>
  
  <p>Has anyone seen this error or managed to configure their postdeployment script to be flexible in this way? Or am I going about this in the wrong way completely?</p>
  
  <p>Thanks,
  Rob</p>
  
  <p>P.S. I've also tried changing this around so that the path to the file is a variable, <a href="https://stackoverflow.com/questions/5653103/sqlcmd-r-path-where-path-is-a-variable">similar to this post</a>. But this gives me an error saying that the path is incorrect.</p>