dbo.Imperium_Verifica_Documentacion

Description

Properties

Name Value
ANSI Nulls ON

True

Quoted Identifier ON

True

Encrypted

False

Execute As
Assembly

Parameters

1
Name Data Type Length Description
@Per int 4

SQL Script

Copy
SET QUOTED_IDENTIFIER, ANSI_NULLS ON
GO

CREATE OR ALTER PROCEDURE  dbo.Imperium_Verifica_Documentacion
@Per int
AS

BEGIN
 SET NOCOUNT ON;

DECLARE @ERRORNUMBER SMALLINT 

  DECLARE LedClientesActivos Cursor
  FOR
  /*
   SELECT  Led_contratos.cliente as IDCliente,IIF(clientes.acceso_ci = 1,'A','V') as modalidad,
   clientes.nombre_cliente
   FROM  clientes INNER JOIN
   led_contratos ON clientes.cliente = led_contratos.cliente
   WHERE clientes.estado_cliente = 'A' and 
   (clientes.acceso_led = 1 or clientes.acceso_ci = 1) 
   and getdate() between led_contratos.vigencia_desde 
   and led_contratos.vigencia_hasta 
   */


  /*
   declare @Per int = 201611
   */

  select distinct contratista, periodo,iif(contratista = contratista_1,'C','S') as led_seccion,contratista_1,cliente from led_DOCS
  where periodo = @Per
  and led_seccion = 'C' and cliente NOT IN (9335603)
  union all
  select distinct contratista, periodo,led_seccion,contratista_1,cliente from led_DOCS
  where periodo = @Per and cliente NOT IN (9335603)
  and led_seccion = 'E'
  union all
  select distinct contratista, periodo,led_seccion,contratista_1,cliente from led_DOCS
  where periodo = @Per and cliente NOT IN (9335603)
  and led_seccion = 'V'
  order by contratista desc



  declare @IDContratistap int
  declare @periodo1 int
  declare @led_seccion1 varchar(1)
  declare @IDCliente1 int
  declare @IDContratista1 int

  Open LedClientesActivos

  

  Fetch NEXT FROM LedClientesActivos INTO @IDContratistaP,@periodo1,@led_seccion1,@IDCliente1,@IDContratista1

  While (@@FETCH_STATUS <> -1)
  BEGIN
  /*
   if (@led_seccion = 'C') 
   begin
   exec Imperium_Carga_Docs_Contratista_Contratista @periodo,@IDCliente,@IDContratista,'A'
   go
   exec Imperium_Carga_Docs_Empleados_Contratista @periodo,@IDCliente,@IDContratista,'V'
   end
   */

   if (@led_seccion1 = 'E') 
   begin
    exec Imperium_Carga_Docs_Empleados_Contratista @periodo1,@IDCliente1,@IDContratistaP,'A'
    exec Imperium_Carga_Docs_Empleados_Contratista @periodo1,@IDCliente1,@IDContratistaP,'V'
   end
   if (@led_seccion1 = 'V') 
   begin
    exec Imperium_Carga_Docs_vehiculoS_Contratista @periodo1,@IDCliente1,@IDContratistaP,'A'
    exec Imperium_Carga_Docs_vehiculos_Contratista @periodo1,@IDCliente1,@IDContratistaP,'V'
   end

  Fetch NEXT FROM LedClientesActivos INTO @IDContratistaP,@periodo1,@led_seccion1,@IDCliente1,@IDContratista1

  END

  CLOSE LedClientesActivos
  DEALLOCATE LedClientesActivos
end

GO

Used By

No items found