title: Passing user defined table parameter to dynamic sql, sp_executesql
body: <p>I need help with passing my "user defined table type" parameter to dynamic sql, sp_executesql.</p>
  
  <p>Here's my sample code:</p>
  
  <pre><code>DECLARE  @str as nvarchar(Max)
  DECLARE @IDLIST AS  ListBigintType  /* this is my table type, with ItemId column (bigint)*/
  
  INSERT INTO @IDLIST
  
  SELECT DISTINCT bigintid FROM tableWithBigInts WITH(NOLOCK)
  
  
  set @str ='select * from SomeTable where ID in (select ItemId from @IdTable) '
  
  EXEC sp_executesql  @str , @ParamDefs, @IdTable = @IDLIST
  </code></pre>
  
  <p>It says : Must declare the table variable "@IdTable"</p>
  
  <p>I can't get this to work, and can't get a workaround with coalesce (for bigints) either because the result will be more than 8000 characters.</p>