无法在存储过程中将变量声明为 TVP 类型

发布于 2024-10-30 14:15:12 字数 1195 浏览 5 评论 0原文

我创建了一个 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 [email protected]
            WHERE MIMO.Status=@okStatus AND
                MIMO.MoveInTime BETWEEN @startDate AND @endDate
            GROUP BY MIMO.UserID

SET NOCOUNT OFF

END
GO

任何人都可以告诉我我做错了什么......我已经尝试了我所知道的,但似乎没有任何效果。

提前致谢。

I have created a TVP and I am trying to use it in a stored proc for my input into stored proc.
the issue is I am not able to create my SP with it. Its says

Msg 137, Level 16, State 1, Procedure uspGetUsersPresentCount, Line 14
Must declare the scalar variable "@usersList".

My SP is

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 [email protected]
            WHERE MIMO.Status=@okStatus AND
                MIMO.MoveInTime BETWEEN @startDate AND @endDate
            GROUP BY MIMO.UserID

SET NOCOUNT OFF

END
GO

can anyone tell me what wrong am I doing ...I have tried what I knew, but nothing seems to work.

Thanks in advanced.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

仲春光 2024-11-06 14:15:12

使用用户列表的别名,或将其放在方括号中:

JOIN @usersList UL ON MIMO.UserID=UL.UserID

JOIN @usersList ON MIMO.UserID=[@usersList].UserID

Either use an alias for the user list, or put it in square braces:

JOIN @usersList UL ON MIMO.UserID=UL.UserID

or

JOIN @usersList ON MIMO.UserID=[@usersList].UserID
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文