Description
Properties
| Name | Value |
|---|---|
| ANSI Nulls ON | True |
| Quoted Identifier ON | True |
| Encrypted | False |
| Execute As | |
| Assembly |
Parameters
1| Name | Data Type | Length | Description |
|---|---|---|---|
| @p_Cuit | varchar | 20 |
SQL Script
Copy
SET QUOTED_IDENTIFIER, ANSI_NULLS ON
GO
CREATE OR ALTER PROCEDURE dbo.obtener_consulta_por_ramos_ant
@p_Cuit varchar(20)
AS
BEGIN
SET NOCOUNT ON;
select ramos.descripcion,count(ramos.descripcion) as cantidad,'entre_0_1' as antiguedad
from contador_consultas
inner join clientes on clientes.cuit = contador_consultas.cuit_cliente
left join ramos on ramos.cod_ramo = clientes.ram_codigo and ramos.tipo_ramo = 'R'
where cuit_consultado = @p_Cuit and (cuit_cliente != '' and tipo_consulta != 'S' and tipo_consulta != 'V')
AND ram_codigo != 99 and datediff(DD,fecha_consulta,getdate()) < 365 and visible = 1 AND user_consulta not in('sidi','f0000','f0001')
group by descripcion
union all
select ramos.descripcion,count(ramos.descripcion) as cantidad,'entre_1_2' as antiguedad
from contador_consultas
inner join clientes on clientes.cuit = contador_consultas.cuit_cliente
left join ramos on ramos.cod_ramo = clientes.ram_codigo and ramos.tipo_ramo = 'R'
where cuit_consultado = @p_Cuit and (cuit_cliente != '' and tipo_consulta != 'S' and tipo_consulta != 'V')
AND ram_codigo != 99 and datediff(DD,fecha_consulta,getdate()) >= 365 AND datediff(DD,fecha_consulta,getdate()) < 730 and visible = 1 AND user_consulta not in('sidi','f0000','f0001')
group by descripcion
union all
select ramos.descripcion,count(ramos.descripcion) as cantidad,'entre_2_5' as antiguedad
from contador_consultas
inner join clientes on clientes.cuit = contador_consultas.cuit_cliente
left join ramos on ramos.cod_ramo = clientes.ram_codigo and ramos.tipo_ramo = 'R'
where cuit_consultado = @p_Cuit and (cuit_cliente != '' and tipo_consulta != 'S' and tipo_consulta != 'V')
AND ram_codigo != 99 and datediff(DD,fecha_consulta,getdate()) >= 730 AND datediff(DD,fecha_consulta,getdate()) <= 1825 and visible = 1 AND user_consulta not in('sidi','f0000','f0001')
group by descripcion
order by descripcion
END
GO
GO
CREATE OR ALTER PROCEDURE dbo.obtener_consulta_por_ramos_ant
@p_Cuit varchar(20)
AS
BEGIN
SET NOCOUNT ON;
select ramos.descripcion,count(ramos.descripcion) as cantidad,'entre_0_1' as antiguedad
from contador_consultas
inner join clientes on clientes.cuit = contador_consultas.cuit_cliente
left join ramos on ramos.cod_ramo = clientes.ram_codigo and ramos.tipo_ramo = 'R'
where cuit_consultado = @p_Cuit and (cuit_cliente != '' and tipo_consulta != 'S' and tipo_consulta != 'V')
AND ram_codigo != 99 and datediff(DD,fecha_consulta,getdate()) < 365 and visible = 1 AND user_consulta not in('sidi','f0000','f0001')
group by descripcion
union all
select ramos.descripcion,count(ramos.descripcion) as cantidad,'entre_1_2' as antiguedad
from contador_consultas
inner join clientes on clientes.cuit = contador_consultas.cuit_cliente
left join ramos on ramos.cod_ramo = clientes.ram_codigo and ramos.tipo_ramo = 'R'
where cuit_consultado = @p_Cuit and (cuit_cliente != '' and tipo_consulta != 'S' and tipo_consulta != 'V')
AND ram_codigo != 99 and datediff(DD,fecha_consulta,getdate()) >= 365 AND datediff(DD,fecha_consulta,getdate()) < 730 and visible = 1 AND user_consulta not in('sidi','f0000','f0001')
group by descripcion
union all
select ramos.descripcion,count(ramos.descripcion) as cantidad,'entre_2_5' as antiguedad
from contador_consultas
inner join clientes on clientes.cuit = contador_consultas.cuit_cliente
left join ramos on ramos.cod_ramo = clientes.ram_codigo and ramos.tipo_ramo = 'R'
where cuit_consultado = @p_Cuit and (cuit_cliente != '' and tipo_consulta != 'S' and tipo_consulta != 'V')
AND ram_codigo != 99 and datediff(DD,fecha_consulta,getdate()) >= 730 AND datediff(DD,fecha_consulta,getdate()) <= 1825 and visible = 1 AND user_consulta not in('sidi','f0000','f0001')
group by descripcion
order by descripcion
END
GO
Depends On
3Used By
No items found