dbo.Imperium_vista_contratista_Ratificacion_Recursos_Subcontratistas

Description

Properties

Name Value
ANSI Nulls ON

True

Quoted Identifier ON

True

Encrypted

False

Execute As
Assembly

Parameters

2
Name Data Type Length Description
@p_contratista int 4
@estado_ratificacion int 4

SQL Script

Copy
SET QUOTED_IDENTIFIER, ANSI_NULLS ON
GO
-- =============================================
-- Author: <Author,,Name>
-- Create date: <Create Date,,>
-- Description: <Description,,>
-- =============================================
CREATE OR ALTER PROCEDURE dbo.Imperium_vista_contratista_Ratificacion_Recursos_Subcontratistas 
 -- Add the parameters for the stored procedure here

 @p_contratista         int,
 @estado_ratificacion       int output

 
AS
BEGIN
 -- SET NOCOUNT ON added to prevent extra result sets from
 -- interfering with SELECT statements.
 SET NOCOUNT ON;

    -- Insert statements for procedure here

 IF (@p_contratista > 0) BEGIN

  IF EXISTS (SELECT contratista FROM led_contratista_periodo
     WHERE contratista = @p_contratista
     AND periodo = dbo.PeriodoVencido()) BEGIN

   DECLARE @empleados INT
   DECLARE @vehiculos INT

   /* asumo todo ratificado */
   SET @estado_ratificacion = 1

   DECLARE Subcontratistas CURSOR FOR

   SELECT  ISNULL(ratif_empleados,0) AS ratif_empleados, 
     ISNULL(ratif_vehiculos,0) AS ratif_vehiculos
   FROM led_subcontratista_periodo
   WHERE contratista = @p_contratista
   AND periodo = dbo.PeriodoVencido()

   OPEN Subcontratistas

   FETCH NEXT FROM Subcontratistas INTO @empleados, @vehiculos

   WHILE (@@FETCH_STATUS = 0) BEGIN
    SET @estado_ratificacion = @estado_ratificacion & @empleados
    SET @estado_ratificacion = @estado_ratificacion & @vehiculos

    FETCH NEXT FROM Subcontratistas INTO @empleados, @vehiculos
   END

   CLOSE Subcontratistas
   DEALLOCATE Subcontratistas


   
  END ELSE

   SET @estado_ratificacion = 1


 END

 
END

GO