IF EXISTS (SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'vendedorparcela') AND EXISTS(SELECT 1 FROM [dbo].[vendedorparcela] vp INNER JOIN [dbo].[parcela] p on p.idparcela = vp.idparcela INNER JOIN [dbo].[repasse] r on r.idrepasse = vp.idrepasse WHERE p.datarec IS NOT NULL AND vp.dataprepagto IS NOT NULL AND r.forma = 1 AND vp.datapgt IS NULL AND vp.dataprepagto != p.datarec)
BEGIN
 update [dbo].[vendedorparcela] set dataprepagto = p.datarec FROM [dbo].[vendedorparcela] vp INNER JOIN [dbo].[parcela] p on p.idparcela = vp.idparcela INNER JOIN [dbo].[repasse] r on r.idrepasse = vp.idrepasse WHERE p.datarec IS NOT NULL AND vp.dataprepagto IS NOT NULL AND r.forma = 1 AND vp.datapgt IS NULL AND vp.dataprepagto != p.datarec
END