use telus; /*verificar convenios antes del 2024*/ if OBJECT_ID('tempdb.dbo.#convenios_revisar') is not null drop table #convenios_revisar select id into #convenios_revisar from db_olympo_web.dbo.convenios_cabecera where code in('002538'); select b.ClaveCatastral, a.* from agcm_2022_tram_liquidaciones_convenio a inner join telus_procesos.dbo.agcm_datos_claves_avaluos b on a.lote_id = b.lote_id where a.id_convenio = (select id from #convenios_revisar) order by lote_id select * from rentas_estado b inner join agcm_2022_tram_liquidaciones_convenio a on b.registro_lote_id = a.lote_id where a.id_convenio = (select id from #convenios_revisar) and b.estado = 1 and estado_registro= 'ACTIVO' order by lote_id select b.* from avaluo_emision_anual_cabecera b inner join agcm_2022_tram_liquidaciones_convenio a on b.lote_id = a.lote_id where a.id_convenio = (select id from #convenios_revisar) and b.esta_convenio = 1 order by b.lote_id --update avaluo_emision_anual_cabecera set esta_convenio = 0 where emision_id in(1947170,1947170)and esta_convenio = 1 --update rentas_estado set estado_registro = 'INACTIVO' where tipo_renta=0 and registro_lote_id = 56354 and estado_registro <> 'INACTIVO' --update agcm_2022_tram_liquidaciones_convenio set estado = 'INACTIVO' where id = 5688 GOTO SALIR DECLARE @id_tram_liq INT, @lote_id INT, @desde INT, @hasta INT DECLARE procesar_cursor CURSOR FOR select --b.ClaveCatastral, a.estado, a.id, a.lote_id, a.desde, a.hasta from agcm_2022_tram_liquidaciones_convenio a inner join telus_procesos.dbo.agcm_datos_claves_avaluos b on a.lote_id = b.lote_id where a.id_convenio = (select id from #convenios_revisar) order by lote_id --SELECT top 1 registro_id FROM rentas_estado where tipo_renta=0 and registro_lote_id = 67325 and estado = 0 order by registro_id desc print 'Fecha Hora Inicio' print getdate() OPEN procesar_cursor FETCH NEXT FROM procesar_cursor INTO @id_tram_liq,@lote_id, @desde, @hasta WHILE @@FETCH_STATUS = 0 BEGIN declare @estado_convenio int = 0 update agcm_2022_tram_liquidaciones_convenio set estado = 'INACTIVO', fecha_actualiza = GETDATE() where id = @id_tram_liq and estado <> 'INACTIVO' update avaluo_emision_anual_cabecera set esta_convenio = 0 where lote_id = @lote_id and ano_id between @desde and @hasta and esta_convenio = 1 and esta_pagado = 1 set @estado_convenio = isnull((select top 1 estado from rentas_estado where tipo_renta=0 and registro_lote_id = @lote_id and estado_registro = 'ACTIVO' and estado <> 0),0) print @estado_convenio if @estado_convenio = 1 begin update rentas_estado set estado_registro = 'INACTIVO' where tipo_renta=0 and registro_lote_id = @lote_id and estado_registro <> 'INACTIVO' insert into rentas_estado(registro_lote_id,tipo_renta,estado,usuario_id,ip,pcname,detalle,estado_registro,fecha) select @lote_id,0,0,18,'127.0.0.1','localhost','Convenio rechazado por inclumplimiento de cuotas mensuales','ACTIVO',GETDATE() end /*ELSE BEGIN update rentas_estado set estado_registro = 'ACTIVO' where registro_id in (SELECT top 1 registro_id FROM rentas_estado where tipo_renta=0 and registro_lote_id = @lote_id and estado = 0 order by registro_id desc) END*/ FETCH NEXT FROM procesar_cursor INTO @id_tram_liq,@lote_id, @desde, @hasta END CLOSE procesar_cursor DEALLOCATE procesar_cursor; print 'Fecha Hora Fin' print getdate() SALIR: