Description
Properties
| Name | Value |
|---|---|
| ANSI Nulls ON | True |
| Quoted Identifier ON | True |
| Encrypted | False |
| Execute As | |
| Assembly |
SQL Script
Copy
SET QUOTED_IDENTIFIER, ANSI_NULLS ON
GO
CREATE OR ALTER PROCEDURE dbo.LN_prueba_petroleros
AS
BEGIN
SET NOCOUNT ON;
-- select top 2 * from country
declare @indic_accion2 int = null
declare @gest int = null
declare @p_cliente int = null
declare @cuit varchar(20) = null
declare @p_contraparte int = 162919
declare @p_user_id int = 1
select @indic_accion2 = LN_indicadores.indicador,
@gest = LN_gestiones.gestion,
@p_cliente = LN_contrapartes.cliente,
@cuit = padrones.identificacion
from LN_indicadores inner join LN_productos on LN_indicadores.producto = LN_productos.producto
inner join LN_familia_productos on LN_productos.producto = LN_familia_productos.producto
inner join LN_contraparte_familias on LN_familia_productos.familia = LN_contraparte_familias.familia
inner join LN_contrapartes on LN_contraparte_familias.contraparte = LN_contrapartes.contraparte
inner join padrones on padrones.id_padron = LN_contrapartes.id_padron
inner join LN_cliente_productos on (LN_contrapartes.cliente = LN_cliente_productos.cliente
and LN_productos.producto = LN_cliente_productos.producto)
inner join LN_gestiones on LN_contrapartes.contraparte = LN_gestiones.contraparte
where LN_contrapartes.contraparte = @p_contraparte
and LN_gestiones.desde <= GETDATE() AND LN_gestiones.hasta >= GETDATE()
and LN_gestiones.vigente = 1
and LN_familia_productos.activo = 1
and LN_cliente_productos.activo = 1
and LN_productos.visible = 1
and LN_contraparte_familias.activo = 1
and LN_indicadores.clave_indicador = 'petroleros'
and LN_productos.producto_id = 'libredeudasindical'
if (@indic_accion2 is not null) begin
declare @txt_ld varchar(100) = null
declare @fecha_ld date = null
declare @numero_ld decimal(20,2)
declare @contratista_ld int = (select id_imperium FROM LN_CONTRAPARTES WHERE contraparte = @p_contraparte)
declare @fechadocumento_ld int = (select max(periodo) from led_docs
where tipo_doc = 1035
and contratista_1 = @contratista_ld
and contratista = contratista_1
and estado_doc = 'V')
declare @periodo_ld date
declare @p_doc_id_ld bigint
if (@fechadocumento_ld is not null)
begin
set @periodo_ld = convert(date,SUBSTRING(convert(char,@fechadocumento_ld),1,4) + '-' +
SUBSTRING(convert(char,@fechadocumento_ld),5,2) + '-01')
set @p_doc_id_ld = (select max(doc_id)
from led_docs
where tipo_doc = 1035
and periodo = @fechadocumento_ld
and contratista_1 = @contratista_ld
and contratista = contratista_1
and estado_doc = 'V'
)
end
declare @campo_ld varchar(100)
declare @campo_tipo_doc int
set @campo_ld = 'SINDICATOPETROLEROSPRIV'
select @campo_tipo_doc = campo_tipo_doc from led_campos_tipo_doc where tipo_doc = 1035 and nombre_campo = @campo_ld
/*select @campo_tipo_doc as campo_tipo_doc*/
select @txt_ld = valor_texto, @numero_ld = valor_numerico, @fecha_ld = valor_fecha
from led_campos_doc
where led_campos_doc.doc_id = @p_doc_id_ld
and led_campos_doc.campo_tipo_doc = @campo_tipo_doc
select @txt_ld = case @numero_ld
when 1 then 'SI'
when 0 then 'NO'
when 2 then 'N/A'
else null end
if not exists (select contraparte, gestion, indicador
from LN_contraparte_indicadores
where contraparte = @p_contraparte
and gestion = @gest
and visible = 1
and indicador = @indic_accion2)
begin
INSERT INTO LN_contraparte_indicadores
(contraparte, gestion, indicador, valor_texto, created, created_by)
VALUES
(@p_contraparte, @gest, @indic_accion2, @txt_ld, GETDATE(), @p_user_id)
end
else
begin
UPDATE LN_contraparte_indicadores SET
valor_texto = @txt_ld,
valor_numerico = @numero_ld,
modified = GETDATE(),
modified_by = @p_user_id
WHERE contraparte = @p_contraparte
AND gestion = @gest
AND indicador = @indic_accion2
and visible = 1
end
select @p_contraparte as contraparte, @gest as gestion, @indic_accion2 as indicador,
@txt_ld as texto, @numero_ld as numero, @fecha_ld as fecha
END
END
GO
GO
CREATE OR ALTER PROCEDURE dbo.LN_prueba_petroleros
AS
BEGIN
SET NOCOUNT ON;
-- select top 2 * from country
declare @indic_accion2 int = null
declare @gest int = null
declare @p_cliente int = null
declare @cuit varchar(20) = null
declare @p_contraparte int = 162919
declare @p_user_id int = 1
select @indic_accion2 = LN_indicadores.indicador,
@gest = LN_gestiones.gestion,
@p_cliente = LN_contrapartes.cliente,
@cuit = padrones.identificacion
from LN_indicadores inner join LN_productos on LN_indicadores.producto = LN_productos.producto
inner join LN_familia_productos on LN_productos.producto = LN_familia_productos.producto
inner join LN_contraparte_familias on LN_familia_productos.familia = LN_contraparte_familias.familia
inner join LN_contrapartes on LN_contraparte_familias.contraparte = LN_contrapartes.contraparte
inner join padrones on padrones.id_padron = LN_contrapartes.id_padron
inner join LN_cliente_productos on (LN_contrapartes.cliente = LN_cliente_productos.cliente
and LN_productos.producto = LN_cliente_productos.producto)
inner join LN_gestiones on LN_contrapartes.contraparte = LN_gestiones.contraparte
where LN_contrapartes.contraparte = @p_contraparte
and LN_gestiones.desde <= GETDATE() AND LN_gestiones.hasta >= GETDATE()
and LN_gestiones.vigente = 1
and LN_familia_productos.activo = 1
and LN_cliente_productos.activo = 1
and LN_productos.visible = 1
and LN_contraparte_familias.activo = 1
and LN_indicadores.clave_indicador = 'petroleros'
and LN_productos.producto_id = 'libredeudasindical'
if (@indic_accion2 is not null) begin
declare @txt_ld varchar(100) = null
declare @fecha_ld date = null
declare @numero_ld decimal(20,2)
declare @contratista_ld int = (select id_imperium FROM LN_CONTRAPARTES WHERE contraparte = @p_contraparte)
declare @fechadocumento_ld int = (select max(periodo) from led_docs
where tipo_doc = 1035
and contratista_1 = @contratista_ld
and contratista = contratista_1
and estado_doc = 'V')
declare @periodo_ld date
declare @p_doc_id_ld bigint
if (@fechadocumento_ld is not null)
begin
set @periodo_ld = convert(date,SUBSTRING(convert(char,@fechadocumento_ld),1,4) + '-' +
SUBSTRING(convert(char,@fechadocumento_ld),5,2) + '-01')
set @p_doc_id_ld = (select max(doc_id)
from led_docs
where tipo_doc = 1035
and periodo = @fechadocumento_ld
and contratista_1 = @contratista_ld
and contratista = contratista_1
and estado_doc = 'V'
)
end
declare @campo_ld varchar(100)
declare @campo_tipo_doc int
set @campo_ld = 'SINDICATOPETROLEROSPRIV'
select @campo_tipo_doc = campo_tipo_doc from led_campos_tipo_doc where tipo_doc = 1035 and nombre_campo = @campo_ld
/*select @campo_tipo_doc as campo_tipo_doc*/
select @txt_ld = valor_texto, @numero_ld = valor_numerico, @fecha_ld = valor_fecha
from led_campos_doc
where led_campos_doc.doc_id = @p_doc_id_ld
and led_campos_doc.campo_tipo_doc = @campo_tipo_doc
select @txt_ld = case @numero_ld
when 1 then 'SI'
when 0 then 'NO'
when 2 then 'N/A'
else null end
if not exists (select contraparte, gestion, indicador
from LN_contraparte_indicadores
where contraparte = @p_contraparte
and gestion = @gest
and visible = 1
and indicador = @indic_accion2)
begin
INSERT INTO LN_contraparte_indicadores
(contraparte, gestion, indicador, valor_texto, created, created_by)
VALUES
(@p_contraparte, @gest, @indic_accion2, @txt_ld, GETDATE(), @p_user_id)
end
else
begin
UPDATE LN_contraparte_indicadores SET
valor_texto = @txt_ld,
valor_numerico = @numero_ld,
modified = GETDATE(),
modified_by = @p_user_id
WHERE contraparte = @p_contraparte
AND gestion = @gest
AND indicador = @indic_accion2
and visible = 1
end
select @p_contraparte as contraparte, @gest as gestion, @indic_accion2 as indicador,
@txt_ld as texto, @numero_ld as numero, @fecha_ld as fecha
END
END
GO
Depends On
12Used By
No items found