我创建了一个TVP,我试图在存储过程中使用它来输入存储过程。 问题是我无法使用它创建我的SP。它说
Msg 137, Level 16, State 1, Procedure uspGetUsersPresentCount, Line 14
Must declare the scalar variable "@usersList".
我的SP
IF EXISTS (SELECT * FROM sysobjects WHERE name = 'uspGetUsersPresentCount')
BEGIN
DROP Procedure [AMProcedures].[uspGetUsersPresentCount]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROC [AMProcedures].[uspGetUsersPresentCount]
(
@usersList AS [AMProcedures].[udfUserListTVP] READONLY,
@startDate DATETIME,
@endDate DATETIME
)
AS
BEGIN
DECLARE @okStatus TINYINT = 4
SET NOCOUNT ON
SELECT MIMO.UserID, COUNT(MIMO.MoveInTime) FROM AMTables.tblUserMoveInMoveOutDetails MIMO
JOIN @usersList ON MIMO.UserID=@usersList.UserID
WHERE MIMO.Status=@okStatus AND
MIMO.MoveInTime BETWEEN @startDate AND @endDate
GROUP BY MIMO.UserID
SET NOCOUNT OFF
END
GO
任何人都可以告诉我,我做错了什么......我已经尝试了我所知道的,但似乎没有任何效果。
先谢谢。
答案 0 :(得分:3)
使用用户列表的别名,或将其放在方括号中:
JOIN @usersList UL ON MIMO.UserID=UL.UserID
或
JOIN @usersList ON MIMO.UserID=[@usersList].UserID