我经常在工作中运行更新,但是,我想开始使用合并命令。不过我还是不太熟悉。
您将如何翻译,或者至少让我了解使用 MERGE 的以下更新语句?
BEGIN TRANSACTION T1
SELECT @@TRANCOUNT;
WITH RADHE2
AS (SELECT ROW_NUMBER () OVER( PARTITION BY Assigned_To, Assigned_To_Descriptor /*,..*/
/* Irrelevant columns removed for brevity*/
ORDER BY Rn_Create_Date DESC, Assigned_To DESC ) AS ID,
*
FROM PivCRM_Prod_Online_ED.dbo.Rn_Appointments
WHERE AN_ACTIVE = 1
AND rn_edit_date > '12 nov 2013'
AND ASSIGNED_TO = 0x000000000000074F
AND notes LIKE 'TAM_Indigo Base_Oct 2013')
--======================================================
--SETTING Appt_Date TO TOMORROW
UPDATE PivCRM_Prod_Online_ED.dbo.Rn_Appointments
SET Appt_Date = '14 NOV 2013'
FROM PivCRM_Prod_Online_ED.dbo.Rn_Appointments R
INNER JOIN RADHE2 R1
ON R.RN_APPOINTMENTS_ID = R1.Rn_APPOINTMENTS_ID
WHERE R1.ID = 1
--COMMIT TRANSACTION T1