如果SQL Server 2008中存储过程的参数超过8000个字符,解决方案是什么


Create Proc GetProductDetails
(
 @ProductId varchar(max)
)
as
begin
select ComplexId from ComplexMaster where ProductId in(@ProductId)
end

@ProductId参数值"1,2,3,4,5……..13524">

由于您似乎使用该参数来传递值列表,因此可能需要考虑改用表值参数而不是varchar

创建表值类型:

CREATE TYPE IdListType AS TABLE (Id int);

将参数定义为该类型(注意必需的READONLY关键字(:

CREATE PROCEDURE GetProductDetails
(
  @ProductIds IdListType READONLY
)
...

从参数中读取值与读取表变量相同。一个例子:

SELECT ComplexId 
FROM ComplexMaster
WHERE ProductId IN (SELECT Id FROM @ProductIds)
;

最新更新