title: TSQL Passing MultiValued Reporting Services Parameter into Dynamic SQL
body: <p><strong>Duplicate of</strong>: <a href="https://stackoverflow.com/questions/712443/tsql-varchar-string-manipulation-problem/712453#712453">TSQL varchar string manipulation</a></p>
  
  <p>I'm building a dynamic SQL statement out of parameters from a reporting services report.  Reporting services passes MutiValue Parameters in a basic CSV format.  For example a list of states may be represented as follows:  AL,CA,NY,TN,VA</p>
  
  <p>In a SQL statement this is OK:  </p>
  
  <pre><code>WHERE customerState In (@StateList) 
  </code></pre>
  
  <p>However, the dynamic variant isn't OK:</p>
  
  <pre><code>SET @WhereClause1 = @WhereClause1 + 'AND customerState IN (' + @StateList + ') '
  </code></pre>
  
  <p>This is because it translates to (invalid SQL):</p>
  
  <pre><code>AND customerState IN (AL,CA,NY,TN,VA)
  </code></pre>
  
  <p>To process it needs something like this:</p>
  
  <pre><code>AND customerState IN ('AL','CA','NY','TN','VA')
  </code></pre>
  
  <p>Is there some cool expression I can use to insert the single quotes into my dynamic SQL?</p>