我需要帮助将我的“用户定义的表类型”参数传递给动态 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”
我无法使其正常工作,也无法使用合并(对于 bigints)获得解决方法,因为结果将超过 8000 个字符。