1
Declare @IsInserted Bit
Declare @Date Datetime=Getdate();
MERGE MASTERSUBJECT AS T
USING #TEMPSUBJECT AS S
ON T.ID=S.ID
WHEN NOT MATCHED BY TARGET THEN
INSERT (TITLE,OREDRNO,DTMADD,[STATUS])
VALUES(S.TITLE,(select MAX(OREDRNO)+1 from
MASTERSUBJECT),@DATE,1)
SET @IsInserted=1 /* IF the record is inserted*/
在上面的代碼中,如果插入成功,我想更新@IsInserted
變量。在SQL Server中使用合併運算符設置變量值
什麼是您當前的錯誤? –
1.你不需要MERGE; 2.在INSERT後使用@@ ROWCOUNT來檢查它 –
對不起但是我想用合併,如果你有任何方法做,那麼請讓我知道 –