title: Passing an array of unique identifiers to a stored procedure
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/337704/parameterizing-an-sql-in-clause">Parameterizing an SQL IN clause?</a><br>
    <a href="https://stackoverflow.com/questions/1069311/passing-an-array-of-parameters-to-a-stored-procedure">Passing an array of parameters to a stored procedure</a>  </p>
  </blockquote>
  
  
  
  <p>I need to pass a collection of unique identifiers to my stored procedure. I wrote this query to test what I want to do:</p>
  
  <pre><code>SELECT  *
  FROM    MyTable
  WHERE   MyTable.TypeId IN ('852D7F39-302A-4E35-94D4-9A0335F8E9DC,1DF6EAA0-D0EC-4E4D-9E6B-1779F0E42A82')
  </code></pre>
  
  <p>This query runs correctly. So I created this stored procedure:</p>
  
  <pre><code>CREATE PROCEDURE [dbo].[MySproc] (
  @TypeIdsList varchar(8000)
  ) AS
  
  BEGIN
  EXEC(
      'SELECT *
      FROM    MyTable
      WHERE   MyTable.TypeId IN (' + @TypeIdsList + ')'
  )
  END
  </code></pre>
  
  <p>But when I execute it with some sample data:</p>
  
  <pre><code>DECLARE @return_value int
  
  EXEC    @return_value = [dbo].[MySproc]
          @TypeIdsList = N'852D7F39-302A-4E35-94D4-9A0335F8E9DC,1DF6EAA0-D0EC-4E4D-9E6B-1779F0E42A82'
  
  SELECT  'Return Value' = @return_value
  
  GO
  </code></pre>
  
  <p>I get this error:</p>
  
  <blockquote>
    <p><em>Incorrect syntax near 'D7F39'.</em></p>
  </blockquote>
  
  <p>Anyone know what I'm doing wrong?</p>