dbo.obtener_comex_pais_test

Description

Properties

Name Value
ANSI Nulls ON

True

Quoted Identifier ON

True

Encrypted

False

Execute As
Assembly

Parameters

1
Name Data Type Length Description
@cuit varchar 13

SQL Script

Copy
SET QUOTED_IDENTIFIER, ANSI_NULLS ON
GO

CREATE OR ALTER PROCEDURE dbo.obtener_comex_pais_test
@cuit varchar(13)

AS
BEGIN
 
SET NOCOUNT ON;
 declare @max_periodo date,@min_periodo date
set @max_periodo  = (select fecha_informacion from fuentes_procesadas where fuente='comex_pais_rubro' and visible =1)
set @min_periodo  = (select DATEADD(month, -12, max(@max_periodo)) as fecha_informacion)
SELECT 'IMPO' as tipo_operacion, nombre,sum(ROUND (fobusd,0)) as fob FROM comex_importaciones 
inner join comex_paises on procedencia = comex_paises.codigo
WHERE CUIT = @cuit and fecha between @min_periodo and @max_periodo
group by nombre 
union all

SELECT 'EXPO' as tipo_operacion,nombre,sum(ROUND (fobusd,0)) as fob FROM comex_exportaciones 
inner join comex_paises on procedencia = comex_paises.codigo
WHERE CUIT = @cuit and fecha between @min_periodo and @max_periodo
group by nombre order by tipo_operacion,fob desc

END

GO

Used By

No items found