dbo.multi_web_2_

Description

Properties

Name Value
ANSI Nulls ON

True

Quoted Identifier ON

True

Encrypted

False

Execute As
Assembly

Parameters

6
Name Data Type Length Description
@accion varchar 50
@p_web_id smallint 2
@p_app_id tinyint 1
@p_cliente int 4
@p_sender varchar 50
@p_servicio int 4

SQL Script

Copy
SET QUOTED_IDENTIFIER, ANSI_NULLS ON
GO
-- =============================================
-- Author: <Author,,Name>
-- Create date: <Create Date,,>

/*

select * from fide_apps

*/

-- Description: <Description,,>
-- =============================================
CREATE OR ALTER PROCEDURE dbo.multi_web_2_
 -- Add the parameters for the stored procedure here

 @accion          varchar(50) = null,
 @p_web_id         smallint = null,
 @p_app_id         tinyint = null,
 @p_cliente         int = null,
 @p_sender         varchar(50) = null, 
 @p_servicio 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

 if (@accion = 'disponibles') begin

  if (@p_app_id is not null)

   select * from multi_web where app_id = @p_app_id and cliente IS NULL and isnull(is_default,0) = 0 order by web_name

  else

   select * from multi_web where cliente IS NULL and isnull(is_default,0) = 0 order by web_name


 end else 

 if (@accion = 'asignar') begin

  if (@p_web_id is not null and @p_cliente is not null) begin

   declare @app_id tinyint
   
   /* al asignar una personalización a un cliente, tengo que sacarlo de todas las otras de la misma app_id */
   select @app_id = app_id from multi_web where web_id = @p_web_id

   update multi_web set cliente = NULL, sender = NULL where app_id = @app_id and cliente = @p_cliente
   
   update multi_web set cliente = @p_cliente , sender = @p_sender where web_id = @p_web_id

  end

 end else

 if (@accion = 'desasignar') begin

  update multi_web set cliente = NULL , sender = NULL where cliente = @p_cliente

 end else

 if (@accion = 'asignados') begin

  select * from multi_web where cliente = @p_cliente order by web_name

 end else

 if (@accion = 'asignables') begin

  select multi_web.*, clientes.nombre_cliente from multi_web left  outer join clientes on multi_web.cliente = clientes.cliente where isnull(is_default,0) = 0 order by web_name

 end

 if (@accion = 'cliente') begin
  if (@p_app_id is not null)
  begin
   if (@p_servicio is null)
    select top 1 multi_web.*, clientes.nombre_cliente
    from multi_web 
    inner join clientes on clientes.cliente = @p_cliente 
    where multi_web.app_id = @p_app_id
    and (multi_web.cliente = @p_cliente or multi_web.cliente is null) 
    and multi_web.active = 1
    order by isnull(multi_web.cliente,0) desc 
   else 
    select top 1 multi_web.*, clientes.nombre_cliente
    from multi_web 
    inner join clientes on clientes.cliente = @p_cliente 
    where multi_web.app_id = @p_app_id
    and multi_web.servicio_contratado = @p_servicio
    and (multi_web.cliente = @p_cliente or multi_web.cliente is null) 
    and multi_web.active = 1
    order by isnull(multi_web.cliente,0) desc 

  end
  else
  begin
   if (@p_servicio is null)
    select top 1 multi_web.*, clientes.nombre_cliente
    from multi_web
    inner join clientes on clientes.cliente = @p_cliente 
    and (multi_web.cliente = @p_cliente or multi_web.cliente is null) 
    and multi_web.active = 1
    order by isnull(multi_web.cliente,0) desc 

   else
    select top 1 multi_web.*, clientes.nombre_cliente
    from multi_web 
    inner join clientes on clientes.cliente = @p_cliente 
    and (multi_web.cliente = @p_cliente or multi_web.cliente is null) 
    and multi_web.servicio_contratado = @p_servicio
    and multi_web.active = 1 
    order by isnull(multi_web.cliente,0) desc 

  end 

 end

 if (@accion = 'mail_cliente') begin
  select top 1 multi_web.*, clientes.nombre_cliente,
  clientes.nombre_cliente, 
  body.spa as body_spa, 
  body.por as body_por, 
  body.eng as body_eng, 
  subj.spa as subj_spa, 
  subj.por as subj_por
  from multi_web 
  inner join clientes on clientes.cliente = @p_cliente 
  left join traducciones body on body.app_id = multi_web.app_id and body.app_key like 'Email%body%'
  left join traducciones subj on subj.app_id = multi_web.app_id and subj.app_key like 'Email%subj%'
  where multi_web.app_id = isnull(@p_app_id,6) -- Para los mails es 6
  and multi_web.servicio_contratado = @p_servicio
  and (multi_web.cliente = @p_cliente or multi_web.cliente is null) 
  and multi_web.active = 1
  order by isnull(multi_web.cliente,0) desc  
 end

 
END

GO

Used By

No items found