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
/*
EXEC Imperium_Regeneracion_Documentacion
*/
CREATE OR ALTER PROCEDURE dbo.Imperium_Regeneracion_Select
AS
BEGIN
SET NOCOUNT ON;
DECLARE @ERRORNUMBER SMALLINT
DECLARE @StartOfMonth DATE
DECLARE @ActualDate DATE
DECLARE @periodoV INT = NULL
DECLARE @periodoVAnt INT = NULL
DECLARE @periodoA INT = NULL
DECLARE @IDCliente int = NULL
DECLARE @Modalidad varchar(1)
DECLARE @NombreCliente varchar(200)
DECLARE @periodoYear INT = NULL
DECLARE @periodoMonth INT = NULL
DECLARE @contratista INT ,@cliente INT ,@contratista_1 INT ,@empleado INT ,@vehiculo INT
DECLARE @led_seccion VARCHAR(1)
SET @periodoYear = convert(varchar(4),datepart(year,getdate()))
SET @periodoMonth = convert(varchar(2),datepart(month,getdate()))
SET @periodoYear = datepart(year,getdate())
SET @periodoMonth = datepart(month,getdate())
SET @periodoA = convert(varchar(4),datepart(year,getdate())) + RIGHT('00' +convert(varchar(2),datepart(month,getdate())),2)
SeT @StartOfMonth = convert(date,DATEADD(month, DATEDIFF(month, 0, getdate()), 0))
set @ActualDate = getdate()
/*
select @StartOfMonth,@ActualDate,@periodoV,@periodoA,@periodoVAnt,@periodoYear as periodoYear,@periodoMonth as periodoMonth
*/
/*
set @periodoMonth = 1
*/
if (@periodoMonth = 1)
begin
set @periodoV = convert(varchar(4),@periodoYear-1) + RIGHT('00' +convert(varchar(2),12),2)
set @periodoVAnt = convert(varchar(4),@periodoYear-1) + RIGHT('00' +convert(varchar(2),11),2)
end
if (@periodoMonth > 1)
begin
set @periodoV = convert(varchar(4),datepart(year,getdate())) + RIGHT('00' +convert(varchar(2),datepart(month,getdate())-1),2)
set @periodoVAnt = convert(varchar(4),datepart(year,getdate())) + RIGHT('00' +convert(varchar(2),datepart(month,getdate())-2),2)
end
set @periodoVAnt = dbo.PeriodoMenosDos()
set @periodoV = dbo.PeriodoVencido()
set @periodoA = dbo.PeriodoAdelantado()
/*
select * from led_contratistas where contratista = 1706
select * from led_contratista_periodo where contratista = 3598
select * from led_contratista_multi where contratista = 1706
select * from led_log where contratista = 3598
select * from led_empleados where empleado = 70213
select * from led_empleados_periodo where empleado = 70213
select * from led_contratista_periodo where fecha_afectacion is null and periodo > 201706
select * from led_subcontratista_periodo where fecha_afectacion is null and periodo > 201706
select * from led_empleados_periodo where fecha_afectacion is null and periodo > 201706
select * from led_vehiculos_periodo where fecha_afectacion is null and periodo > 201706
*/
/*
select @StartOfMonth as startofmonth,@ActualDate as actualdate,@periodoV as periodoV,@periodoA as periodoA,@periodoVAnt as periodoVANT,@periodoYear as periodoYear,@periodoMonth as periodoMonth
*/
select contratista,cliente,contratista_1,null as empleado,null as vehiculo,iif(contratista = contratista_1,'C','S') as led_seccion
from led_contratistas where created > getdate() -1 and estado_contratista='A'
union all
select contratista,cliente,contratista_1,null as empleado,null as vehiculo,iif(contratista = contratista_1,'C','S') as led_seccion
from led_contratista_multi where (created > getdate() -1 or modified > getdate()-1) and activo=1 and vigencia_desde < getdate() and (vigencia_hasta > getdate() or vigencia_hasta is null)
union all
select contratista,cliente,contratista_1,empleado,null as vehiculo,'E' AS led_seccion
from led_empleados where created > getdate() -1 and estado_empleado='A'
union all
select contratista,cliente,contratista_1,empleado,null as vehiculo,'E' AS led_seccion
from led_empleado_multi where (created > getdate() -1 or modified > getdate()-1) and activo=1 and vigencia_desde < getdate() and (vigencia_hasta > getdate() or vigencia_hasta is null)
or empleado in (select distinct empleado from led_empleados_periodo where fecha_afectacion is null and periodo > 201706)
union all
select contratista,cliente,contratista_1,null as empleado,vehiculo,'V' AS led_seccion
from led_vehiculos where created > getdate() -1 and estado_vehiculo='A' or vehiculo in (select distinct vehiculo from led_vehiculos_periodo where fecha_afectacion is null and periodo > 201706)
/*
select distinct contratista,cliente,contratista_1,iif(contratista = contratista_1,'C','S') as led_seccion from led_contratistas where created > getdate() -90 and estado_contratista='A'
union all
select distinct contratista,cliente,contratista_1,iif(contratista = contratista_1,'C','S') as led_seccion from led_contratista_multi where (created > getdate() -90 or modified > getdate()-90) and activo=1 and vigencia_desde < getdate() and (vigencia_hasta > getdate() or vigencia_hasta is null)
union all
select distinct contratista,cliente,contratista_1,'E' AS led_seccion from led_empleados where created > getdate() -90 and estado_empleado='A'
union all
select distinct contratista,cliente,contratista_1,'E' AS led_seccion from led_empleado_multi where (created > getdate() -90 or modified > getdate()-90) and activo=1 and vigencia_desde < getdate() and (vigencia_hasta > getdate() or vigencia_hasta is null)
union all
select distinct contratista,cliente,contratista_1,'V' AS led_seccion from led_vehiculos where created > getdate() -90 and estado_vehiculo='A'
group by contratista,cliente,contratista_1
order by contratista desc
*/
/*
truncate table led_reprocesa_docs
go
*/
/*
insert into led_reprocesa_docs (contratista,cliente,contratista_1,led_seccion,empleado,vehiculo)
select distinct contratista,cliente,contratista_1,iif(contratista = contratista_1,'C','S') as led_seccion,null as empleado,null as vehiculo from led_contratistas where created > getdate() -90 and estado_contratista='A'
union all
select distinct contratista,cliente,contratista_1,iif(contratista = contratista_1,'C','S') as led_seccion,null as empleado,null as vehiculo from led_contratista_multi where (created > getdate() -90 or modified > getdate()-90) and activo=1 and vigencia_desde < getdate() and (vigencia_hasta > getdate() or vigencia_hasta is null)
union all
select distinct contratista,cliente,contratista_1,'E' AS led_seccion,empleado,null as vehiculo from led_empleados where created > getdate() -90 and estado_empleado='A'
union all
select distinct contratista,cliente,contratista_1,'E' AS led_seccion,empleado,null as vehiculo from led_empleado_multi where (created > getdate() -90 or modified > getdate()-90) and activo=1 and vigencia_desde < getdate() and (vigencia_hasta > getdate() or vigencia_hasta is null)
union all
select distinct contratista,cliente,contratista_1,'V' AS led_seccion,null as empleado,vehiculo from led_vehiculos where created > getdate() -90 and estado_vehiculo='A'
/*
group by contratista,cliente,contratista_1,empleado,vehiculo
*/
order by contratista desc
*/
select top 50 contratista,cliente,contratista_1,empleado,vehiculo,led_seccion,idRepro
from led_reprocesa_docs
where procesado = 0
order by contratista desc
/*
where contratista_1 = 2739
*/
END
GO
GO
/*
EXEC Imperium_Regeneracion_Documentacion
*/
CREATE OR ALTER PROCEDURE dbo.Imperium_Regeneracion_Select
AS
BEGIN
SET NOCOUNT ON;
DECLARE @ERRORNUMBER SMALLINT
DECLARE @StartOfMonth DATE
DECLARE @ActualDate DATE
DECLARE @periodoV INT = NULL
DECLARE @periodoVAnt INT = NULL
DECLARE @periodoA INT = NULL
DECLARE @IDCliente int = NULL
DECLARE @Modalidad varchar(1)
DECLARE @NombreCliente varchar(200)
DECLARE @periodoYear INT = NULL
DECLARE @periodoMonth INT = NULL
DECLARE @contratista INT ,@cliente INT ,@contratista_1 INT ,@empleado INT ,@vehiculo INT
DECLARE @led_seccion VARCHAR(1)
SET @periodoYear = convert(varchar(4),datepart(year,getdate()))
SET @periodoMonth = convert(varchar(2),datepart(month,getdate()))
SET @periodoYear = datepart(year,getdate())
SET @periodoMonth = datepart(month,getdate())
SET @periodoA = convert(varchar(4),datepart(year,getdate())) + RIGHT('00' +convert(varchar(2),datepart(month,getdate())),2)
SeT @StartOfMonth = convert(date,DATEADD(month, DATEDIFF(month, 0, getdate()), 0))
set @ActualDate = getdate()
/*
select @StartOfMonth,@ActualDate,@periodoV,@periodoA,@periodoVAnt,@periodoYear as periodoYear,@periodoMonth as periodoMonth
*/
/*
set @periodoMonth = 1
*/
if (@periodoMonth = 1)
begin
set @periodoV = convert(varchar(4),@periodoYear-1) + RIGHT('00' +convert(varchar(2),12),2)
set @periodoVAnt = convert(varchar(4),@periodoYear-1) + RIGHT('00' +convert(varchar(2),11),2)
end
if (@periodoMonth > 1)
begin
set @periodoV = convert(varchar(4),datepart(year,getdate())) + RIGHT('00' +convert(varchar(2),datepart(month,getdate())-1),2)
set @periodoVAnt = convert(varchar(4),datepart(year,getdate())) + RIGHT('00' +convert(varchar(2),datepart(month,getdate())-2),2)
end
set @periodoVAnt = dbo.PeriodoMenosDos()
set @periodoV = dbo.PeriodoVencido()
set @periodoA = dbo.PeriodoAdelantado()
/*
select * from led_contratistas where contratista = 1706
select * from led_contratista_periodo where contratista = 3598
select * from led_contratista_multi where contratista = 1706
select * from led_log where contratista = 3598
select * from led_empleados where empleado = 70213
select * from led_empleados_periodo where empleado = 70213
select * from led_contratista_periodo where fecha_afectacion is null and periodo > 201706
select * from led_subcontratista_periodo where fecha_afectacion is null and periodo > 201706
select * from led_empleados_periodo where fecha_afectacion is null and periodo > 201706
select * from led_vehiculos_periodo where fecha_afectacion is null and periodo > 201706
*/
/*
select @StartOfMonth as startofmonth,@ActualDate as actualdate,@periodoV as periodoV,@periodoA as periodoA,@periodoVAnt as periodoVANT,@periodoYear as periodoYear,@periodoMonth as periodoMonth
*/
select contratista,cliente,contratista_1,null as empleado,null as vehiculo,iif(contratista = contratista_1,'C','S') as led_seccion
from led_contratistas where created > getdate() -1 and estado_contratista='A'
union all
select contratista,cliente,contratista_1,null as empleado,null as vehiculo,iif(contratista = contratista_1,'C','S') as led_seccion
from led_contratista_multi where (created > getdate() -1 or modified > getdate()-1) and activo=1 and vigencia_desde < getdate() and (vigencia_hasta > getdate() or vigencia_hasta is null)
union all
select contratista,cliente,contratista_1,empleado,null as vehiculo,'E' AS led_seccion
from led_empleados where created > getdate() -1 and estado_empleado='A'
union all
select contratista,cliente,contratista_1,empleado,null as vehiculo,'E' AS led_seccion
from led_empleado_multi where (created > getdate() -1 or modified > getdate()-1) and activo=1 and vigencia_desde < getdate() and (vigencia_hasta > getdate() or vigencia_hasta is null)
or empleado in (select distinct empleado from led_empleados_periodo where fecha_afectacion is null and periodo > 201706)
union all
select contratista,cliente,contratista_1,null as empleado,vehiculo,'V' AS led_seccion
from led_vehiculos where created > getdate() -1 and estado_vehiculo='A' or vehiculo in (select distinct vehiculo from led_vehiculos_periodo where fecha_afectacion is null and periodo > 201706)
/*
select distinct contratista,cliente,contratista_1,iif(contratista = contratista_1,'C','S') as led_seccion from led_contratistas where created > getdate() -90 and estado_contratista='A'
union all
select distinct contratista,cliente,contratista_1,iif(contratista = contratista_1,'C','S') as led_seccion from led_contratista_multi where (created > getdate() -90 or modified > getdate()-90) and activo=1 and vigencia_desde < getdate() and (vigencia_hasta > getdate() or vigencia_hasta is null)
union all
select distinct contratista,cliente,contratista_1,'E' AS led_seccion from led_empleados where created > getdate() -90 and estado_empleado='A'
union all
select distinct contratista,cliente,contratista_1,'E' AS led_seccion from led_empleado_multi where (created > getdate() -90 or modified > getdate()-90) and activo=1 and vigencia_desde < getdate() and (vigencia_hasta > getdate() or vigencia_hasta is null)
union all
select distinct contratista,cliente,contratista_1,'V' AS led_seccion from led_vehiculos where created > getdate() -90 and estado_vehiculo='A'
group by contratista,cliente,contratista_1
order by contratista desc
*/
/*
truncate table led_reprocesa_docs
go
*/
/*
insert into led_reprocesa_docs (contratista,cliente,contratista_1,led_seccion,empleado,vehiculo)
select distinct contratista,cliente,contratista_1,iif(contratista = contratista_1,'C','S') as led_seccion,null as empleado,null as vehiculo from led_contratistas where created > getdate() -90 and estado_contratista='A'
union all
select distinct contratista,cliente,contratista_1,iif(contratista = contratista_1,'C','S') as led_seccion,null as empleado,null as vehiculo from led_contratista_multi where (created > getdate() -90 or modified > getdate()-90) and activo=1 and vigencia_desde < getdate() and (vigencia_hasta > getdate() or vigencia_hasta is null)
union all
select distinct contratista,cliente,contratista_1,'E' AS led_seccion,empleado,null as vehiculo from led_empleados where created > getdate() -90 and estado_empleado='A'
union all
select distinct contratista,cliente,contratista_1,'E' AS led_seccion,empleado,null as vehiculo from led_empleado_multi where (created > getdate() -90 or modified > getdate()-90) and activo=1 and vigencia_desde < getdate() and (vigencia_hasta > getdate() or vigencia_hasta is null)
union all
select distinct contratista,cliente,contratista_1,'V' AS led_seccion,null as empleado,vehiculo from led_vehiculos where created > getdate() -90 and estado_vehiculo='A'
/*
group by contratista,cliente,contratista_1,empleado,vehiculo
*/
order by contratista desc
*/
select top 50 contratista,cliente,contratista_1,empleado,vehiculo,led_seccion,idRepro
from led_reprocesa_docs
where procesado = 0
order by contratista desc
/*
where contratista_1 = 2739
*/
END
GO
Depends On
11Used By
No items found