dbo.Imperium_buscar_tipos_contratista

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
@p_tipo_contratista int 4

SQL Script

Copy
SET QUOTED_IDENTIFIER, ANSI_NULLS ON
GO
-- =============================================
-- Author: <Author,,Name>
-- Create date: <Create Date,,>
-- Description: <Description,,>
-- =============================================
/*
exec Imperium_buscar_tipos_contratista 10708

*/


CREATE OR ALTER PROCEDURE dbo.Imperium_buscar_tipos_contratista
 -- Add the parameters for the stored procedure here
 

 --- ESTE PARAMETRO REFIERE AL CONTRATISTA PRINCIPAL
 @p_contratista           int = NULL,

 --- ESTE PARAMETRO CORRESPONDE AL TIPO DEL SUBCONTRATISTA QUE DEPENDE DEL PRINICIPAL, PARA OBTENER TIPOS DE ALTA HABILITADO
 @p_tipo_contratista          int = null
 
AS
BEGIN
 -- SET NOCOUNT ON added to prevent extra result sets from
 -- interfering with SELECT statements.
 SET NOCOUNT ON;

    -- Insert statements for procedure here
 declare @tipo_contratista int, @cliente int, @tipos_hab tinyint = 0

 
 -- OBTENER TIPOS DE SUBCONTRATISTA HABILITADOS PARA UN CONTRATISTA EN PARTICULAR 

 if (@p_contratista is not null AND @p_tipo_contratista is null) begin

  select @tipo_contratista = tipo_contratista , @cliente = cliente
  from led_contratistas where contratista = @p_contratista
  
  /* select tipo_contratista , cliente from led_contratistas where contratista = 9448*/

  /*
   select @tipo_contratista = tipo_subcontratista, @cliente = led_contratistas.cliente  from led_contratistas 
   inner join led_cliente_subcontratista_tipo_contratista on led_contratistas.tipo_contratista=led_cliente_subcontratista_tipo_contratista.tipo_contratista
   where led_contratistas.contratista = @p_contratista
   */

  /*select * from led_cliente_subcontratista_tipo_contratista where cliente = 9936068 and tipo_contratista = 253
   delete led_cliente_subcontratista_tipo_contratista where cliente = 9936068 and tipo_contratista = 253 and tipo_subcontratista=253
   */


  /*insert into led_cliente_subcontratista_tipo_contratista (cliente,tipo_subcontratista,tipo_contratista) values (9936068,253,253)*/
  

  --- chequeo que no haya tipos exclusivos de subcontratista para el tipo de contratista 

  if not exists (select * from led_cliente_subcontratista_tipo_contratista
      where cliente = @cliente
      and tipo_contratista = @tipo_contratista) begin


   select led_cliente_contratista.cliente, led_cliente_contratista.tipo_contratista,
   clientes.nombre_cliente, led_tipos_contratista.nombre_tipo_contratista
   from led_cliente_contratista
   inner join clientes on led_cliente_contratista.cliente = clientes.cliente
   inner join led_tipos_contratista on led_cliente_contratista.tipo_contratista = led_tipos_contratista.tipo_contratista
   where led_cliente_contratista.cliente = @cliente
   and led_tipos_contratista.es_principal = 1
   and led_cliente_contratista.activo = 1
   group by led_cliente_contratista.cliente, led_cliente_contratista.tipo_contratista,
   clientes.nombre_cliente, led_tipos_contratista.nombre_tipo_contratista
   order by led_tipos_contratista.nombre_tipo_contratista

  end else begin

   --- tipos de subcontratista exclusivo para tipo de contratista
   select led_cliente_contratista.cliente, led_cliente_contratista.tipo_contratista,
   clientes.nombre_cliente, led_tipos_contratista.nombre_tipo_contratista
   from led_cliente_contratista
   inner join clientes on led_cliente_contratista.cliente = clientes.cliente
   inner join led_tipos_contratista on led_cliente_contratista.tipo_contratista = led_tipos_contratista.tipo_contratista
   inner join led_cliente_subcontratista_tipo_contratista on (led_cliente_contratista.cliente  = led_cliente_subcontratista_tipo_contratista.cliente
                and led_cliente_contratista.tipo_contratista = led_cliente_subcontratista_tipo_contratista.tipo_subcontratista
                and led_cliente_subcontratista_tipo_contratista.tipo_contratista = @tipo_contratista)
   where led_cliente_contratista.cliente = @cliente
   and led_tipos_contratista.es_principal = 1
   and led_cliente_contratista.activo = 1
   group by led_cliente_contratista.cliente, led_cliente_contratista.tipo_contratista,
   clientes.nombre_cliente, led_tipos_contratista.nombre_tipo_contratista
   order by led_tipos_contratista.nombre_tipo_contratista




  end


 end
 
 -- OBTENER TIPOS DE ALTA HABILITADO PARA UN CONTRATISTA Y TIPO DE SUBCONTRATISTA

 if (@p_contratista is not null AND @p_tipo_contratista is not null) begin

  -- El tipo de contratista del principal
  select @tipo_contratista = tipo_contratista , @cliente = cliente
  from led_contratistas where contratista = @p_contratista

  -- Obtener los tipos de alta para el tipo del subcontratista
  select led_tipos_alta.tipo_alta, led_tipos_alta.nombre_tipo_alta
  from led_tipos_alta inner join led_cliente_contratista
  on led_tipos_alta.tipo_alta = led_cliente_contratista.tipo_alta
  where led_cliente_contratista.cliente = @cliente
  and led_cliente_contratista.tipo_contratista = @p_tipo_contratista
  and led_cliente_contratista.activo = 1
  group by led_tipos_alta.tipo_alta, led_tipos_alta.nombre_tipo_alta
  order by led_tipos_alta.nombre_tipo_alta  




 end


END
GO

Used By

No items found