我创建了一个名为account
的表:
我还创建了一个名为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
提供值:
然后抛出错误:
Msg 206,Level 16,State 2,Procedure usp_InsertorUpadte,Line 2 操作数类型冲突:nvarchar与account_TT不兼容
(1行受影响)
为什么会抛出此错误,如何解决导致错误的问题?
答案 0 :(得分:3)
您无法使用SSMS提供的GUI执行使用表值参数的存储过程。您需要手动编写测试:
DECLARE @account_TT AS account_TT
INSERT INTO @account_TT VALUES('IT')
EXEC usp_InsertorUpadte @account_TT