Código SQL:
Ver original
CREATE PROCEDURE [dbo].[UPSERT_SURVEYS] --WITH EXECUTE AS OWNER AS SET NOCOUNT ON BEGIN --BEGIN TRY MERGE INTO tblSurveys WITH (HOLDLOCK) AS tgt USING [dbo].[tblSurveysStaging] src ON (tgt.[CASE_ID] + tgt.[COMPLETED] = src.[CASE_ID] + src.[COMPLETED]) WHEN MATCHED THEN UPDATE SET TGT.[FCR] = SRC.[FCR], TGT.[CSAT]= SRC.[CSAT], TGT.[COMMENTS] = SRC.[COMMENTS], TGT.[CUSTOMER_EMAIL] = SRC.[CUSTOMER_EMAIL], TGT.[COMPLETED] = SRC.[COMPLETED], TGT.[TITLE] = SRC.[TITLE], TGT.[AGENT_EMAIL] = SRC.[AGENT_EMAIL], TGT.[COUNTRY] = SRC.[COUNTRY] WHEN NOT MATCHED BY TARGET THEN INSERT ( [CASE_ID] ,[FCR] ,[CSAT] ,[COMMENTS] ,[CUSTOMER_EMAIL] ,[COMPLETED] ,[TITLE] ,[AGENT_EMAIL] ,[COUNTRY]) VALUES ( SRC.[CASE_ID] ,SRC.[FCR] ,SRC.[CSAT] ,SRC.[COMMENTS] ,SRC.[CUSTOMER_EMAIL] ,SRC.[COMPLETED] ,SRC.[TITLE] ,SRC.[AGENT_EMAIL] ,SRC.[COUNTRY]); DELETE FROM tblSurveysStaging; DELETE FROM tblSurveys WHERE dateDIFF(DAY,CONVERT(DATETIME,Completed),CONVERT(DATETIME,getdate()))>365; --END TRY --BEGIN CATCH --DELETE FROM tblSurveysStaging; --END CATCH END
O se imaginan que otra cosa puede estar bloqueando...Se los agradezco muchísimo...