ALTER PROCEDURE [MDM].[PRO_COPYTABLE]
@TableName nvarchar(50)
AS
BEGIN
DECLARE @delsql nvarchar(2000)
DECLARE @insertsql nvarchar(2000)
BEGIN
SET @delsql='DELETE cp FROM ITSV.mdm.'+@TableName+ ' cp WHERE
NOT EXISTS(SELECT * FROM mdm.'
+@TableName+' WHERE UPDATE_DATETIME =
cp.UPDATE_DATETIME)'
PRINT @delsql
SET @insertsql='INSERT ITSV.mdm.'+@TableName+' SELECT * FROM
mdm.'+@TableName+' c where not exists(SELECT * FROM
ITSV.mdm.'
+@TableName+ ' cp WHERE cp.GUID = c.GUID)'
PRINT @insertsql
EXEC(@delsql)
EXEC(@insertsql)
END
END