DELETE FROM asurnet.dbo.CONTRATOS

SET IDENTITY_INSERT asurnet.dbo.CONTRATOS ON;
INSERT INTO asurnet.dbo.CONTRATOS
(CNT_Id, CNT_Alias, CNT_AutCodigo, CNT_TipoOBJ, CNT_Nombre, CNT_NumeroContrato, CNT_Version, CNT_Fecha, CNT_Estado, CNT_Tipo,
CNT_SRC, CNT_ControlFirma, CNT_Observaciones, CNT_TipoPlantilla, CNT_PathPlantilla, CNT_IdPlantilla, USR_Id_FC, USR_Id_FM, CNT_FC, 
CNT_FM, CNT_SEPAMetodoPago)
SELECT A.CNT_Id, A.CNT_Alias, A.CNT_AutCodigo, A.CNT_TipoOBJ, A.CNT_Nombre, A.CNT_NumeroContrato, A.CNT_Version, A.CNT_Fecha, A.CNT_Estado, A.CNT_Tipo,
A.CNT_SRC, A.CNT_ControlFirma, A.CNT_Observaciones, A.CNT_TipoPlantilla, A.CNT_PathPlantilla, A.CNT_IdPlantilla, C.UseId, D.UseId, A.CNT_FC, 
A.CNT_FM, A.CNT_SEPAMetodoPago
FROM vsegbas.dbo.CONTRATOS A
LEFT JOIN (
	SELECT A.USR_Id, B.UseId FROM vsegbas.dbo.USUARIOS A
	INNER JOIN tssbase.dbo.Usuarios B
	ON A.USR_Login = B.UseLog COLLATE Modern_Spanish_CI_AI
) C ON A.USR_Id_FC = C.USR_Id
LEFT JOIN (
	SELECT A.USR_Id, B.UseId FROM vsegbas.dbo.USUARIOS A
	INNER JOIN tssbase.dbo.Usuarios B
	ON A.USR_Login = B.UseLog COLLATE Modern_Spanish_CI_AI
) D ON A.USR_Id_FM = D.USR_Id
SET IDENTITY_INSERT asurnet.dbo.CONTRATOS OFF;