「ユーザー定義のテーブルタイプ」パラメーターを動的SQL、sp_executesqlに渡す際にサポートが必要です。
これが私のサンプルコードです:
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
それは言う:テーブル変数「@IdTable」を宣言しなければならない
結果が8000文字を超えるため、これを機能させることができず、coalesce(bigintsの場合)を回避することもできません。