dbo.Imperium_calcula_doc_id_anterior

Description

Properties

Name Value
ANSI Nulls ON

True

Quoted Identifier ON

True

Encrypted

False

Execute As
Assembly

Parameters

2
Name Data Type Length Description
@periodo int 4
@periodicidad varchar 1

SQL Script

Copy
SET QUOTED_IDENTIFIER, ANSI_NULLS ON
GO

CREATE OR ALTER PROCEDURE dbo.Imperium_calcula_doc_id_anterior
@periodo int,
@periodicidad varchar(1)
AS


declare @periodo_ant int = @periodo-1
BEGIN
       
update LD2 set replicated_doc_id = ld.doc_id
/*,
INGRESADO = LD.INGRESADO,
INGRESADO_POR = LD.INGRESADO_POR,
VERIFICADO=LD.VERIFICADO,
VERIFICADO_POR=LD.VERIFICADO_POR,
RECHAZADO=LD.RECHAZADO,
RECHAZADO_POR=LD.RECHAZADO_POR,
TEXTO_RECHAZO=LD.TEXTO_RECHAZO
*/

from led_docs LD inner join led_docs LD2 on (ld.tipo_doc = ld2.tipo_doc and ld.contratista=ld2.contratista
AND ISNULL(ld.empleado,0) = isnull(ld2.empleado,0) and ISNULL(ld.vehiculo,0) = isnull(ld2.vehiculo,0) and 
ld.cliente = ld2.cliente
and ld2.periodo = @periodo)
where LD.doc_id_lista is null and LD.periodo in (@periodo_ant) and LD.tipo_doc in (
select tipo_doc from 
led_tipos_doc where periodicidad in (@periodicidad)) and LD.contratista_1 > 0 
/*
and LD.estado_doc in ('V','R','I')
*/




/*


select ld.doc_id as IDANT,ld.periodo as PERANT,LD.tipo_doc as TIPOANT,LD.contratista as contrant,LD.empleado as empleANT,ld.estado_doc as estadoANT,ld.fecha_vigencia as vigenciANT,
LD2.doc_id,ld.tipo_doc,ld.contratista,ld.empleado,ld.periodo,ld2.estado_doc,ld2.fecha_vigencia,getdate() as fecha
from led_docs LD inner join led_docs LD2 on (ld.tipo_doc = ld2.tipo_doc and ld.contratista=ld2.contratista
AND ISNULL(ld.empleado,0) = isnull(ld2.empleado,0) and ISNULL(ld.vehiculo,0) = isnull(ld2.vehiculo,0) and 
ld.cliente = ld2.cliente and ld2.periodo = 201707 )
where LD.doc_id_lista is null and LD.periodo in (201706)  and LD.tipo_doc in (select tipo_doc from 
led_tipos_doc where periodicidad in ('A')) and LD.contratista_1 > 0
/*and LD2.doc_id = 4933654086*/

and LD2.replicated_doc_id is null
and LD2.estado_doc in ('V')
and LD.estado_doc in ('V')
and LD2.ingresado is null
and LD2.fecha_vigencia > getdate()


upd--ate LD2 set replicated_doc_id = ld.doc_id
from led_docs LD inner join led_docs LD2 on (ld.tipo_doc = ld2.tipo_doc and ld.contratista=ld2.contratista
AND ISNULL(ld.empleado,0) = isnull(ld2.empleado,0) and ISNULL(ld.vehiculo,0) = isnull(ld2.vehiculo,0) and 
ld.cliente = ld2.cliente and ld2.periodo = 201707 )
where LD.doc_id_lista is null and LD.periodo in (201706)  and LD.tipo_doc in (select tipo_doc from 
led_tipos_doc where periodicidad in ('A')) and LD.contratista_1 > 0
/*and LD2.doc_id = 4933654086*/

and LD2.replicated_doc_id is null
and LD2.estado_doc in ('V')
and LD.estado_doc in ('V')
and LD2.ingresado is null
and LD2.fecha_vigencia > getdate()

*/







END

GO

Used By

No items found