我想给一个标识符数组作为存储过程的参数。
存储过程如下所示:
ALTER PROCEDURE [dbo].[SearchPerson]
@personType INT = NULL,
@city NVARCHAR(64) = NULL,
@siteIds IntegerList READONLY,
-- some other params...
AS
SELECT
-- some fields...
FROM dbo.PersonView AS pv
WHERE
(
(@personType IS NULL OR pv.PersonType = @personType) AND
(@city IS NULL OR pv.City LIKE '%' + @city + '%') AND
(pv.SiteId in (SELECT si.Value FROM @siteIds AS si)) AND
-- some other params filter...
)
用户表类型如下所示:
CREATE TYPE [dbo].[IntegerList] AS TABLE(
[Value] [int] NULL
)
当我从 SSMS 中的脚本调用存储过程时(我最初从 .NET 代码调用它时遇到同样的问题):
DECLARE @siteIds AS IntegerList,
@personType AS INT = 1
INSERT INTO @siteIds VALUES (1)
EXEC [dbo].[SearchPerson] @personType, @siteIds
我得到了错误:
操作数类型冲突:int 与 IntegerList 不兼容