执行存储过程时操作数类型冲突错误

时间:2016-12-21 07:45:12

标签: sql-server stored-procedures

我创建了一个名为account的表:

TableDefinition

我还创建了一个名为account_TT的表类型:

CREATE TYPE account_TT AS TABLE
(
    AccountID nvarchar(50)
)

然后我创建了一个存储过程来插入/更新帐户表中的记录:

ALTER PROCEDURE [dbo].[usp_InsertorUpadte] 
@account_TT AS account_TT READONLY

AS
BEGIN
    SET NOCOUNT ON;

    BEGIN TRANSACTION;

    MERGE dbo.[account] prj
    USING @account_TT tt
    ON prj.AccountID = tt.AccountID
    WHEN MATCHED THEN UPDATE SET prj.CounterSeq = prj.CounterSeq+1
    WHEN NOT MATCHED THEN INSERT (AccountID,CounterSeq)
    VALUES (tt.AccountID, 1);

    COMMIT TRANSACTION;
END

要测试此存储过程,我右键单击它并选择Execute Stored Procedure并为参数@account_TT提供值:

ExecuteWithParameter

然后抛出错误:

  

Msg 206,Level 16,State 2,Procedure usp_InsertorUpadte,Line 2   操作数类型冲突:nvarchar与account_TT不兼容

     

(1行受影响)

为什么会抛出此错误,如何解决导致错误的问题?

1 个答案:

答案 0 :(得分:3)

您无法使用SSMS提供的GUI执行使用表值参数的存储过程。您需要手动编写测试:

DECLARE @account_TT AS account_TT
INSERT INTO @account_TT VALUES('IT')
EXEC usp_InsertorUpadte @account_TT