表类型参数的列名无效

时间:2017-10-24 08:41:01

标签: sql sql-server-2008 stored-procedures ssrs-2008

我有一个表类型,在存储过程中用于过滤掉值。

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”无效

1 个答案:

答案 0 :(得分:3)

这是一个表,所以正确的语法是

SELECT *
FROM  MYTABLE
WHERE date Between @RundateStart And @RundateEnd 
  AND Ids in (SELECT PackageId FROM @CreationIds)

这假设表@CreationIds中的每一行都是一个ID,可以映射到Ids中与MYTABLE相同的类型。