微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

sql-server – 如何将udtt传递到SQL Server Management Studio中的存储过程

我有一个SP prc_Foo_Delete具有以下签名:
ALTER PROCEDURE [prc_Foo_Delete]
    @fooIds [int_udtt] READONLY,@deleteReason int,@comment nvarchar(512),@deletedBy nvarchar(128)

int_udtt定义为:

CREATE TYPE [int_udtt] AS TABLE(
    [Id] [int] NOT NULL,PRIMARY KEY CLUSTERED 
(
    [Id] ASC
)WITH (IGnorE_DUP_KEY = OFF)
)

我试图在Management Studio中使用以下脚本调用此SP:

DECLARE @return_value int
EXEC    @return_value = [prc_Foo_Delete]
        @fooIds = 3,@deleteReason = 2,@comment = N'asfdasdf',@deletedBy = N'asdfa'

SELECT  'Return Value' = @return_value
GO

我得到的错误是:操作数类型冲突:int与int_udtt不兼容.如何传递int或int列表来调用此工具(我知道如何在代码中执行,但不在Management Studio中).

解决方法

由于您已将用户定义的类型定义为存储过程的参数,因此在调用存储过程时也需要使用该用户定义的类型!你不能只发一个INT而不是….

尝试这样的东西:

-- define an instance of your user-defined table type
DECLARE @IDs [int_udtt]

-- fill some values into that table
INSERT INTO @IDs VALUES(3),(5),(17),(42)

-- call your stored proc
DECLARE @return_value int
EXEC    @return_value = [prc_Foo_Delete]
        @fooIds = @IDs,-- pass in that UDT table type here!
        @deleteReason = 2,@deletedBy = N'asdfa'

SELECT  'Return Value' = @return_value
GO

原文地址:https://www.jb51.cc/mssql/82292.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐