BEGIN MERGE PGENIUS..DISC_CLS_FND AS TARGET USING (SELECT SEQ,ISVALID, DISC_ID, DISC_CLS_CODE,DECLAREDATE FROM #INSERTED_DISC_CLS WHERE DISC_TYPE=2) AS SOURCE (SEQ,ISVALID,DISC_ID, DISC_CLS_CODE,DECLAREDATE) ON (TARGET.DISC_ID = SOURCE.DISC_ID and target.Cls_code=source.disc_cls_code) WHEN MATCHED THEN UPDATE SET MTIME =GETDATE() ,ISVALID=SOURCE.ISVALID ,DISC_ID=SOURCE.DISC_ID ,CLS_CODE =source.DISC_CLS_CODE ,DECLAREDATE =source.DECLAREDATE WHEN NOT MATCHED THEN INSERT ( SEQ,MTIME,ISVALID, DISC_ID,CLS_CODE,DECLAREDATE) VALUES (SOURCE.SEQ,GETDATE(),SOURCE.ISVALID,SOURCE.DISC_ID,source.DISC_CLS_CODE,DECLAREDATE) ; END