我有一个表类型,在存储过程中用于过滤掉值。
CREATE TYPE PackageIdType AS TABLE
(
PackageId VARCHAR(150)
);
我的存储过程是:
CREATE PROCEDURE [dbo].[spLocalGetValuesFromTable]
@RundateStart datetime,
@RundateEnd datetime,
@CreationIds PackageIdType READONLY
AS
SELECT *
FROM MYTABLE
WHERE date BETWEEN @RundateStart AND @RundateEnd
AND Ids IN (@CreationIds)
但是当我运行此错误时:
Msg 207,Level 16,State 1,Procedure spLocalGetValuesFromTable,Line - [Batch Start Line 0]
列名称“@CreationIds”无效
答案 0 :(得分:3)
这是一个表,所以正确的语法是
SELECT *
FROM MYTABLE
WHERE date Between @RundateStart And @RundateEnd
AND Ids in (SELECT PackageId FROM @CreationIds)
这假设表@CreationIds
中的每一行都是一个ID,可以映射到Ids
中与MYTABLE
相同的类型。