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
--exec obtener_grafico_exportaciones '30500548041'
CREATE OR ALTER PROCEDURE dbo.obtener_grafico_exportaciones
@p_Cuit varchar(20)
AS
BEGIN
SET NOCOUNT ON;
/*
declare @max_periodo date,@min_periodo date
set @max_periodo = (select max(fecha_informacion) as fecha_informacion from fuentes_procesadas where fuente='comex_pais_rubro' and visible =1)
set @min_periodo = (select DATEADD(month, -24, max(fecha_informacion)) as fecha_informacion from fuentes_procesadas where fuente='comex_pais_rubro' and visible =1)
select
isnull(sum(round(fobusd,0)),0) as valor_mensual,
(CAST(YEAR(fecha) AS VARCHAR) + CAST(RIGHT(CONCAT('00',MONTH(fecha)),2) AS VARCHAR)) as periodo
from comex_exportaciones
where cuit = @p_Cuit
and fecha between @min_periodo and @max_periodo
group by (CAST(YEAR(fecha) AS VARCHAR) + CAST(RIGHT(CONCAT('00',MONTH(fecha)),2) AS VARCHAR))
*/
declare @max_periodo date, @min_periodo date
declare @max_periodo_uno date, @max_periodo_ultimo date, @min_periodo_uno date
set @max_periodo = (select max(fecha_informacion) as fecha_informacion from fuentes_procesadas where fuente='comex_pais_rubro' and visible = 1)
set @max_periodo_uno = convert(date,SUBSTRING(convert(char,@max_periodo),0,8)+'-01')
set @max_periodo_ultimo = DATEADD(day, -1, (DATEADD(month, +1, @max_periodo_uno)))
set @min_periodo = (select DATEADD(month, -24, max(fecha_informacion)) as fecha_informacion from fuentes_procesadas where fuente='comex_pais_rubro' and visible =1)
set @min_periodo_uno = convert(date,SUBSTRING(convert(char,@min_periodo),0,8)+'-01')
select
isnull(sum(round(replace(fobusd,',','.'),0)),0) as valor_mensual,
(CAST(YEAR(fecha) AS VARCHAR) + CAST(RIGHT(CONCAT('00',MONTH(fecha)),2) AS VARCHAR)) as periodo
--from comex_exportaciones
/* 24/01/2025: Porque hay muchos registros que se repiten muchas veces */
from (select distinct cuit, procedencia, fobusd, posicion, fecha
from comex_exportaciones
where cuit = @p_Cuit
and fecha between @min_periodo_uno and @max_periodo_ultimo
) ce
/**/
where cuit = @p_Cuit
and fecha between @min_periodo_uno and @max_periodo_ultimo
group by (CAST(YEAR(fecha) AS VARCHAR) + CAST(RIGHT(CONCAT('00',MONTH(fecha)),2) AS VARCHAR))
END
GO
GO
--exec obtener_grafico_exportaciones '30500548041'
CREATE OR ALTER PROCEDURE dbo.obtener_grafico_exportaciones
@p_Cuit varchar(20)
AS
BEGIN
SET NOCOUNT ON;
/*
declare @max_periodo date,@min_periodo date
set @max_periodo = (select max(fecha_informacion) as fecha_informacion from fuentes_procesadas where fuente='comex_pais_rubro' and visible =1)
set @min_periodo = (select DATEADD(month, -24, max(fecha_informacion)) as fecha_informacion from fuentes_procesadas where fuente='comex_pais_rubro' and visible =1)
select
isnull(sum(round(fobusd,0)),0) as valor_mensual,
(CAST(YEAR(fecha) AS VARCHAR) + CAST(RIGHT(CONCAT('00',MONTH(fecha)),2) AS VARCHAR)) as periodo
from comex_exportaciones
where cuit = @p_Cuit
and fecha between @min_periodo and @max_periodo
group by (CAST(YEAR(fecha) AS VARCHAR) + CAST(RIGHT(CONCAT('00',MONTH(fecha)),2) AS VARCHAR))
*/
declare @max_periodo date, @min_periodo date
declare @max_periodo_uno date, @max_periodo_ultimo date, @min_periodo_uno date
set @max_periodo = (select max(fecha_informacion) as fecha_informacion from fuentes_procesadas where fuente='comex_pais_rubro' and visible = 1)
set @max_periodo_uno = convert(date,SUBSTRING(convert(char,@max_periodo),0,8)+'-01')
set @max_periodo_ultimo = DATEADD(day, -1, (DATEADD(month, +1, @max_periodo_uno)))
set @min_periodo = (select DATEADD(month, -24, max(fecha_informacion)) as fecha_informacion from fuentes_procesadas where fuente='comex_pais_rubro' and visible =1)
set @min_periodo_uno = convert(date,SUBSTRING(convert(char,@min_periodo),0,8)+'-01')
select
isnull(sum(round(replace(fobusd,',','.'),0)),0) as valor_mensual,
(CAST(YEAR(fecha) AS VARCHAR) + CAST(RIGHT(CONCAT('00',MONTH(fecha)),2) AS VARCHAR)) as periodo
--from comex_exportaciones
/* 24/01/2025: Porque hay muchos registros que se repiten muchas veces */
from (select distinct cuit, procedencia, fobusd, posicion, fecha
from comex_exportaciones
where cuit = @p_Cuit
and fecha between @min_periodo_uno and @max_periodo_ultimo
) ce
/**/
where cuit = @p_Cuit
and fecha between @min_periodo_uno and @max_periodo_ultimo
group by (CAST(YEAR(fecha) AS VARCHAR) + CAST(RIGHT(CONCAT('00',MONTH(fecha)),2) AS VARCHAR))
END
GO
Depends On
2Used By
No items found