dbo.carga_consultas_informix

Description

Properties

Name Value
ANSI Nulls ON

True

Quoted Identifier ON

True

Encrypted

False

Execute As
Assembly

Parameters

1
Name Data Type Length Description
@parametro int 4

SQL Script

Copy
SET QUOTED_IDENTIFIER, ANSI_NULLS ON
GO
/*
exec [carga_consultas_informix] 1
exec [carga_consultas_informix] 2
*/

CREATE OR ALTER PROCEDURE dbo.carga_consultas_informix 
@parametro int
AS
BEGIN
 SET NOCOUNT ON
 declare @desde datetime, 
         @hasta datetime,
   @periodo varchar(7),
   @siguiente datetime 

 if (@parametro = 1) -- Consultas de compactos 
 begin 
  /*set @desde = (select fecha from consultas_a_informix)
   set @hasta = getdate()
   update consultas_a_informix set fecha = @hasta
   */

  set @desde = '2024-02-01 00:00:00'
  set @hasta = '2024-02-20 23:59:59:59'

  select distinct b.cli_codigo, CONVERT(varchar(10),a.created,103) as fecha, cuit_consultado
  from usuarios_consumos a, users b
  where b.user_id = a.user_id
  and created between @desde and @hasta
  and isnull(cuit_consultado,'') != ''
  and id_producto != 16
  and cli_codigo not in (50001,3466166) -- clientes de cortesia
  order by b.cli_codigo, CONVERT(varchar(10),a.created,103)
 end 
 else  -- Monitoreos 
 begin 

  set @hasta = getdate()
  set @periodo = (select FORMAT(@hasta, 'yyyy-MM'))
  --set @siguiente = dateadd(month,1,convert(datetime, @periodo + '-01 00:00:00')) --> las tiene vigentes al mes que viene
  set @siguiente = convert(datetime, @periodo + '-01 00:00:00') --> las tenía vigentes este mes, en algún momento

  select b.cli_codigo, @periodo as manten_periodo, COUNT(distinct a.cuit) as nro_manten_fir, 0 as nro_manten_fis
  from monitoreos a, clientes b
  where b.cliente = a.cliente
  and (a.fecha_vigencia_mantenimiento is null or a.fecha_vigencia_mantenimiento >= @siguiente)
  and isnull(a.cuit,'') != ''
  and cli_codigo not in (50001,3466166) -- clientes de cortesia
  and a.visible = 1
  and exists (select * from clientes_productos where cliente = a.cliente and id_producto = 16)
  group by b.cli_codigo, b.nombre_cliente
  order by b.cli_codigo
 end 
END 


 /* Primero: 
  Correr este select cambiando las fechas por las que correspondan
  Se pasa el resultado de este select a la tabla sidi:consultas de informix
 
  select distinct b.cli_codigo, CONVERT(varchar(10),a.created,103) as fecha, cuit_consultado
  from usuarios_consumos a, users b
  where b.user_id = a.user_id
  and convert(date, created) between '2018-07-26' and '2018-07-30'
  and isnull(cuit_consultado,'') != ''
  and id_producto != 16
  and cli_codigo not in (50001,3466166) -- clientes de cortesia
  --and cli_codigo = 15355
  order by b.cli_codigo, CONVERT(varchar(10),a.created,103)
 
 */


/* segundo:
------------------------------------------------------------------
-- Para pasar las consultas de Mantenimiento hay que correr esto: 
------------------------------------------------------------------
-- Pasar los datos al informix
-- En el informix antes borrar los datos del mes a facturar (por si se hicieron cargar a lo largo del mes)
--
-- delete from manten_nro where manten_periodo = "2018-07"
--
-- despues cargar estos datos. (cambiando las fechas!)

select b.cli_codigo, '2018-08' as  manten_periodo, COUNT(distinct a.cuit) as nro_manten_fir, 0 as nro_manten_fis
from monitoreos a, clientes b
where b.cliente = a.cliente
and (a.fecha_vigencia_mantenimiento is null or a.fecha_vigencia_mantenimiento > '2018-09-01 00:00:00')
and isnull(a.cuit,'') != ''
and cli_codigo not in (50001,3466166) -- clientes de cortesia
and a.visible = 1
and exists (select * from clientes_productos where cliente = a.cliente and id_producto = 16)
group by b.cli_codigo, b.nombre_cliente
order by b.cli_codigo
*/



/* -- Consultas de verificaciones de datos
select * from clientes where cli_codigo = 111

select * from monitoreos where cliente = 1313127297 order by fecha_desde

select distinct cuit from monitoreos where cliente = 344136695 and visible = 1
update monitoreos set visible = 0 where cliente = 445560292 and fecha_desde < '2016-06-01'

select * from productos

select distinct cuit from monitoreos a where cliente = (select cliente from clientes where cli_codigo = 8907)
and visible = 1
and (fecha_vigencia_mantenimiento is null or fecha_vigencia_mantenimiento > '2017-08-01 00:00:00')
and exists (select * from clientes_productos where cliente = a.cliente and id_producto = 16)
*/


GO

Used By

No items found