0
我有一個表格類型,我發送作爲我的存儲過程中的變量。MERGE和條件匹配
CREATE TYPE OperationKeysTableType AS TABLE
(
[KeysId] [int] NOT NULL,
[OperationId] [int] NOT NULL,
[IsChecked] [bit] NOT NULL
)
然後,我想用這個表做一個搜索,如果他們匹配與否,插入或刪除,但只有當它沒有被選中,像這樣:
MERGE INTO dbo.tblOperationKeys AS T
USING (SELECT VT.KeysId, VT.OperationId as OperationId FROM @ValuesTable AS VT) AS S
ON T.KeysId = S.KeysId AND T.OperationId = S.OperationId
WHEN MATCHED AND S.IsChecked = 0 THEN --DELETE
DELETE
WHEN NOT MATCHED THEN--INSERT
INSERT (KeysId, OperationId) VALUES (S.KeysId, S.OperationId)
OUTPUT $action AS ChangesMade, inserted.OperationKeysId AS new_OperationKeysId, deleted.OperationKeysId AS old_OperationKeysId;
我的問題是, SQL告訴我IsChecked無效。任何想法我做錯了什麼?
你仍然沒有得到這個工作? – 2013-03-06 15:59:59