title: using Table variable with sp_executesql
body: <p>I have a query that contain a table variable:</p>
  
  <pre><code>DECLARE @Selects    XML ;
  SET @Selects='&lt;Selects&gt;&lt;Select&gt;&lt;Q_ID&gt;1&lt;/Q_ID&gt;&lt;Q_DESC&gt;nima1&lt;/Q_DESC&gt;&lt;/Select&gt;&lt;Select&gt;&lt;Q_ID&gt;2&lt;/Q_ID&gt;&lt;Q_DESC&gt;nima2&lt;/Q_DESC&gt;&lt;/Select&gt;&lt;Select&gt;&lt;Q_ID&gt;3&lt;/Q_ID&gt;&lt;Q_DESC&gt;nima3&lt;/Q_DESC&gt;&lt;/Select&gt;&lt;/Selects&gt;'
  
  DECLARE @QuestionID     NVARCHAR(10);
  SET @QuestionID='a5';
  
  DECLARE @TblSelect  TABLE 
  (
      Q_ID            INT,
      Q_DESC          NVARCHAR(500)
  )
  
  INSERT INTO @TblSelect
  (
      Q_ID,Q_DESC
  )
  SELECT  Q_Select.value('(Q_ID)[1]', 'int') AS 'Q_ID',
          Q_Select.value('(Q_DESC)[1]', 'nvarchar(500)') AS 'Q_DESC'
  FROM    @Selects.nodes('/Selects/Select') AS AllSelects(Q_Select) 
  
  DECLARE @Query      NVARCHAR(4000);
  SET @Query=N'SELECT Q_ID,COUNT(Q_ID) FROM @TblSelect LEFT OUTER JOIN tblbase tb ON @TblSelect.Q_ID = @Col_Select group by Q_ID';
  
  EXECUTE sp_executesql @Query,@TblSelect,@Col_Select
  </code></pre>
  
  <p>How I can pass the table variable to my query?</p>