How to pass udtt into a stored procedure in SQL Server Management Studio

前端 未结 1 858
萌比男神i
萌比男神i 2021-02-01 18:08

I have a SP prc_Foo_Delete which has the following signature:

ALTER PROCEDURE [prc_Foo_Delete]
    @fooIds [int_udtt] READONLY,
    @deleteReason int,
    @comme         


        
1条回答
  •  无人共我
    2021-02-01 18:15

    Since you've defined your user defined type as a parameter on the stored procedure, you need to use that user-defined type, too, when calling the stored procedure! You cannot just send in a single INT instead....

    Try something like this:

    -- 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,
            @comment = N'asfdasdf',
            @deletedBy = N'asdfa'
    
    SELECT  'Return Value' = @return_value
    GO
    

    0 讨论(0)
提交回复
热议问题