Description
Properties
| Name | Value |
|---|---|
| ANSI Nulls ON | True |
| Quoted Identifier ON | True |
| Encrypted | False |
| Execute As | |
| Assembly |
Parameters
3| Name | Data Type | Length | Description |
|---|---|---|---|
| @p_cliente | int | 4 | |
| @p_lista | varchar | -1 | |
| @p_servicio_contratado | int | 4 |
SQL Script
Copy
SET QUOTED_IDENTIFIER, ANSI_NULLS ON
GO
-- =============================================
-- Author: <Author,,Name>
-- Create date: <Create Date,,>
-- Description: <Description,,>
-- =============================================
/*
[LN_panel_control_excel] 7855254
select * from users where username = 'LEDDEMO'
select * from clientes where cli_codigo =5680
*/
CREATE OR ALTER PROCEDURE dbo.LN_panel_control_excel
-- Add the parameters for the stored procedure here
@p_cliente int,
@p_lista varchar(max) = null,
@p_servicio_contratado int = 47
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_cliente is not null) begin
declare @cant_ps int = (select count(distinct isnull(pais_servicio,''))
FROM LN_contrapartes
inner join LN_gestiones on LN_gestiones.contraparte = LN_contrapartes.contraparte
INNER JOIN LN_contraparte_familias ON LN_contrapartes.contraparte = LN_contraparte_familias.contraparte
INNER JOIN LN_familias ON LN_contraparte_familias.familia = LN_familias.familia and LN_familias.cliente = ln_contrapartes.cliente
where LN_contrapartes.cliente = @p_cliente
and LN_contrapartes.activo = 1
and LN_contrapartes.subcontratista = 0
AND LN_familias.visible = 1
and LN_gestiones.desde <= GETDATE() and LN_gestiones.hasta >= GETDATE()
and LN_contrapartes.servicio_contratado = @p_servicio_contratado )
if (isnull(@p_lista,'') = '')
SELECT LN_contrapartes.contraparte, LN_contrapartes.cliente, LN_contrapartes.id_padron,
identificadores.country_code, country.country_name, padrones.nombre_persona,
identificadores.abreviatura, padrones.identificador, padrones.identificacion as numero, clientes.nombre_cliente,
LN_contraparte_familias.codigo_agrupacion,
LN_contraparte_familias.estado_homologacion,
LN_contraparte_familias.activo,
LN_contrapartes.nombre_contacto, LN_contrapartes.email_contacto, LN_contrapartes.telefono_contacto,
LN_contrapartes.activo, LN_contrapartes.vigencia_desde, LN_contrapartes.vigencia_hasta,
LN_familias.familia, LN_familias.nombre_familia, LN_familias.visible,
CONVERT(VARCHAR(19), LN_contraparte_familias.created, 121) AS created,
CONVERT(VARCHAR(19), LN_contraparte_familias.modified, 121) AS modified,
users.first_name + ' ' + users.last_name AS created_by_user,
users1.first_name + ' ' + users1.last_name AS modified_by_user,
convert(varchar(10),ln_gestiones.desde,103) as inicio_gestion,
datediff(dd,ln_gestiones.desde,convert(date,getdate())) AS dias_gestion,
dd.detalle as detalle_killer,
isnull(pais_serv.country_name,'') as pais_servicio,
@cant_ps as cant_ps,
ln_contrapartes.pais_servicio as ps,
ln_contrapartes.email_ejecutivo_cuenta
FROM LN_contrapartes
inner join LN_gestiones on LN_gestiones.contraparte = LN_contrapartes.contraparte
INNER JOIN padrones ON LN_contrapartes.id_padron = padrones.id_padron
INNER JOIN identificadores ON padrones.identificador = identificadores.identificador
INNER JOIN country ON identificadores.country_code = country.country_code
LEFT OUTER JOIN country pais_serv ON ln_contrapartes.pais_servicio = pais_serv.country_code
INNER JOIN LN_contraparte_familias ON LN_contrapartes.contraparte = LN_contraparte_familias.contraparte
INNER JOIN LN_familias ON LN_contraparte_familias.familia = LN_familias.familia and LN_familias.cliente = ln_contrapartes.cliente
INNER JOIN clientes ON LN_contrapartes.cliente = clientes.cliente
LEFT OUTER JOIN users ON LN_contraparte_familias.created_by = users.user_id
LEFT OUTER JOIN users as users1 ON LN_contraparte_familias.modified_by = users1.user_id
left join (SELECT contraparte, gestion, detalle=STUFF(
(SELECT distinct '; ' + detalle_killer AS [text()]
FROM ln_score_detalle_killer XT
WHERE XT.contraparte = T.contraparte and XT.visible = 1 and Xt.gestion = T.gestion
FOR XML PATH('')), 1, 2, '')
FROM ln_score_detalle_killer T where T.visible = 1
GROUP BY contraparte,gestion) dd on (dd.contraparte = ln_contrapartes.contraparte and dd.gestion = ln_gestiones.gestion)
where LN_contrapartes.cliente = @p_cliente
and LN_contrapartes.activo = 1
and LN_contrapartes.subcontratista = 0
AND LN_familias.visible = 1
AND LN_contraparte_familias.activo = 1
and LN_gestiones.desde <= GETDATE() and LN_gestiones.hasta >= GETDATE()
and LN_contrapartes.servicio_contratado = @p_servicio_contratado
--ORDER BY country.country_name, LN_familias.nombre_familia, padrones.nombre_persona
else
SELECT LN_contrapartes.contraparte, LN_contrapartes.cliente, LN_contrapartes.id_padron,
identificadores.country_code, country.country_name, padrones.nombre_persona,
identificadores.abreviatura, padrones.identificador, padrones.identificacion as numero, clientes.nombre_cliente,
LN_contraparte_familias.codigo_agrupacion,
LN_contraparte_familias.estado_homologacion,
LN_contraparte_familias.activo,
LN_contrapartes.nombre_contacto, LN_contrapartes.email_contacto, LN_contrapartes.telefono_contacto,
LN_contrapartes.activo, LN_contrapartes.vigencia_desde, LN_contrapartes.vigencia_hasta,
LN_familias.familia, LN_familias.nombre_familia, LN_familias.visible,
CONVERT(VARCHAR(19), LN_contraparte_familias.created, 121) AS created,
CONVERT(VARCHAR(19), LN_contraparte_familias.modified, 121) AS modified,
users.first_name + ' ' + users.last_name AS created_by_user,
users1.first_name + ' ' + users1.last_name AS modified_by_user,
convert(varchar(10),ln_gestiones.desde,103) as inicio_gestion,
datediff(dd,ln_gestiones.desde,convert(date,getdate())) AS dias_gestion,
dd.detalle as detalle_killer,
isnull(pais_serv.country_name,'') as pais_servicio,
@cant_ps as cant_ps,
ln_contrapartes.pais_servicio as ps,
ln_contrapartes.email_ejecutivo_cuenta
FROM LN_contrapartes
inner join LN_gestiones on LN_gestiones.contraparte = LN_contrapartes.contraparte
INNER JOIN padrones ON LN_contrapartes.id_padron = padrones.id_padron
INNER JOIN identificadores ON padrones.identificador = identificadores.identificador
INNER JOIN country ON identificadores.country_code = country.country_code
LEFT OUTER JOIN country pais_serv ON ln_contrapartes.pais_servicio = pais_serv.country_code
INNER JOIN LN_contraparte_familias ON LN_contrapartes.contraparte = LN_contraparte_familias.contraparte
INNER JOIN LN_familias ON LN_contraparte_familias.familia = LN_familias.familia and LN_familias.cliente = ln_contrapartes.cliente
INNER JOIN clientes ON LN_contrapartes.cliente = clientes.cliente
LEFT OUTER JOIN users ON LN_contraparte_familias.created_by = users.user_id
INNER JOIN dbo.DelimitedSplit8K(@p_lista, ',') Contrapartes ON LN_contrapartes.contraparte = Contrapartes.Item
left join (SELECT contraparte, gestion, detalle=STUFF(
(SELECT distinct '; ' + detalle_killer AS [text()]
FROM ln_score_detalle_killer XT
WHERE XT.contraparte = T.contraparte and XT.visible = 1 and XT.gestion = T.gestion
FOR XML PATH('')), 1, 2, '')
FROM ln_score_detalle_killer T where T.visible = 1
GROUP BY contraparte,gestion) dd on (dd.contraparte = ln_contrapartes.contraparte and dd.gestion = LN_gestiones.gestion)
LEFT OUTER JOIN users as users1 ON LN_contraparte_familias.modified_by = users1.user_id
where LN_contrapartes.cliente = @p_cliente
and LN_contrapartes.activo = 1
AND LN_familias.visible = 1
AND LN_contraparte_familias.activo = 1
and LN_gestiones.desde <= GETDATE() and LN_gestiones.hasta >= GETDATE()
and LN_contrapartes.servicio_contratado = @p_servicio_contratado
order by itemNumber
--ORDER BY country.country_name, LN_familias.nombre_familia, padrones.nombre_persona
end
END
GO
GO
-- =============================================
-- Author: <Author,,Name>
-- Create date: <Create Date,,>
-- Description: <Description,,>
-- =============================================
/*
[LN_panel_control_excel] 7855254
select * from users where username = 'LEDDEMO'
select * from clientes where cli_codigo =5680
*/
CREATE OR ALTER PROCEDURE dbo.LN_panel_control_excel
-- Add the parameters for the stored procedure here
@p_cliente int,
@p_lista varchar(max) = null,
@p_servicio_contratado int = 47
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_cliente is not null) begin
declare @cant_ps int = (select count(distinct isnull(pais_servicio,''))
FROM LN_contrapartes
inner join LN_gestiones on LN_gestiones.contraparte = LN_contrapartes.contraparte
INNER JOIN LN_contraparte_familias ON LN_contrapartes.contraparte = LN_contraparte_familias.contraparte
INNER JOIN LN_familias ON LN_contraparte_familias.familia = LN_familias.familia and LN_familias.cliente = ln_contrapartes.cliente
where LN_contrapartes.cliente = @p_cliente
and LN_contrapartes.activo = 1
and LN_contrapartes.subcontratista = 0
AND LN_familias.visible = 1
and LN_gestiones.desde <= GETDATE() and LN_gestiones.hasta >= GETDATE()
and LN_contrapartes.servicio_contratado = @p_servicio_contratado )
if (isnull(@p_lista,'') = '')
SELECT LN_contrapartes.contraparte, LN_contrapartes.cliente, LN_contrapartes.id_padron,
identificadores.country_code, country.country_name, padrones.nombre_persona,
identificadores.abreviatura, padrones.identificador, padrones.identificacion as numero, clientes.nombre_cliente,
LN_contraparte_familias.codigo_agrupacion,
LN_contraparte_familias.estado_homologacion,
LN_contraparte_familias.activo,
LN_contrapartes.nombre_contacto, LN_contrapartes.email_contacto, LN_contrapartes.telefono_contacto,
LN_contrapartes.activo, LN_contrapartes.vigencia_desde, LN_contrapartes.vigencia_hasta,
LN_familias.familia, LN_familias.nombre_familia, LN_familias.visible,
CONVERT(VARCHAR(19), LN_contraparte_familias.created, 121) AS created,
CONVERT(VARCHAR(19), LN_contraparte_familias.modified, 121) AS modified,
users.first_name + ' ' + users.last_name AS created_by_user,
users1.first_name + ' ' + users1.last_name AS modified_by_user,
convert(varchar(10),ln_gestiones.desde,103) as inicio_gestion,
datediff(dd,ln_gestiones.desde,convert(date,getdate())) AS dias_gestion,
dd.detalle as detalle_killer,
isnull(pais_serv.country_name,'') as pais_servicio,
@cant_ps as cant_ps,
ln_contrapartes.pais_servicio as ps,
ln_contrapartes.email_ejecutivo_cuenta
FROM LN_contrapartes
inner join LN_gestiones on LN_gestiones.contraparte = LN_contrapartes.contraparte
INNER JOIN padrones ON LN_contrapartes.id_padron = padrones.id_padron
INNER JOIN identificadores ON padrones.identificador = identificadores.identificador
INNER JOIN country ON identificadores.country_code = country.country_code
LEFT OUTER JOIN country pais_serv ON ln_contrapartes.pais_servicio = pais_serv.country_code
INNER JOIN LN_contraparte_familias ON LN_contrapartes.contraparte = LN_contraparte_familias.contraparte
INNER JOIN LN_familias ON LN_contraparte_familias.familia = LN_familias.familia and LN_familias.cliente = ln_contrapartes.cliente
INNER JOIN clientes ON LN_contrapartes.cliente = clientes.cliente
LEFT OUTER JOIN users ON LN_contraparte_familias.created_by = users.user_id
LEFT OUTER JOIN users as users1 ON LN_contraparte_familias.modified_by = users1.user_id
left join (SELECT contraparte, gestion, detalle=STUFF(
(SELECT distinct '; ' + detalle_killer AS [text()]
FROM ln_score_detalle_killer XT
WHERE XT.contraparte = T.contraparte and XT.visible = 1 and Xt.gestion = T.gestion
FOR XML PATH('')), 1, 2, '')
FROM ln_score_detalle_killer T where T.visible = 1
GROUP BY contraparte,gestion) dd on (dd.contraparte = ln_contrapartes.contraparte and dd.gestion = ln_gestiones.gestion)
where LN_contrapartes.cliente = @p_cliente
and LN_contrapartes.activo = 1
and LN_contrapartes.subcontratista = 0
AND LN_familias.visible = 1
AND LN_contraparte_familias.activo = 1
and LN_gestiones.desde <= GETDATE() and LN_gestiones.hasta >= GETDATE()
and LN_contrapartes.servicio_contratado = @p_servicio_contratado
--ORDER BY country.country_name, LN_familias.nombre_familia, padrones.nombre_persona
else
SELECT LN_contrapartes.contraparte, LN_contrapartes.cliente, LN_contrapartes.id_padron,
identificadores.country_code, country.country_name, padrones.nombre_persona,
identificadores.abreviatura, padrones.identificador, padrones.identificacion as numero, clientes.nombre_cliente,
LN_contraparte_familias.codigo_agrupacion,
LN_contraparte_familias.estado_homologacion,
LN_contraparte_familias.activo,
LN_contrapartes.nombre_contacto, LN_contrapartes.email_contacto, LN_contrapartes.telefono_contacto,
LN_contrapartes.activo, LN_contrapartes.vigencia_desde, LN_contrapartes.vigencia_hasta,
LN_familias.familia, LN_familias.nombre_familia, LN_familias.visible,
CONVERT(VARCHAR(19), LN_contraparte_familias.created, 121) AS created,
CONVERT(VARCHAR(19), LN_contraparte_familias.modified, 121) AS modified,
users.first_name + ' ' + users.last_name AS created_by_user,
users1.first_name + ' ' + users1.last_name AS modified_by_user,
convert(varchar(10),ln_gestiones.desde,103) as inicio_gestion,
datediff(dd,ln_gestiones.desde,convert(date,getdate())) AS dias_gestion,
dd.detalle as detalle_killer,
isnull(pais_serv.country_name,'') as pais_servicio,
@cant_ps as cant_ps,
ln_contrapartes.pais_servicio as ps,
ln_contrapartes.email_ejecutivo_cuenta
FROM LN_contrapartes
inner join LN_gestiones on LN_gestiones.contraparte = LN_contrapartes.contraparte
INNER JOIN padrones ON LN_contrapartes.id_padron = padrones.id_padron
INNER JOIN identificadores ON padrones.identificador = identificadores.identificador
INNER JOIN country ON identificadores.country_code = country.country_code
LEFT OUTER JOIN country pais_serv ON ln_contrapartes.pais_servicio = pais_serv.country_code
INNER JOIN LN_contraparte_familias ON LN_contrapartes.contraparte = LN_contraparte_familias.contraparte
INNER JOIN LN_familias ON LN_contraparte_familias.familia = LN_familias.familia and LN_familias.cliente = ln_contrapartes.cliente
INNER JOIN clientes ON LN_contrapartes.cliente = clientes.cliente
LEFT OUTER JOIN users ON LN_contraparte_familias.created_by = users.user_id
INNER JOIN dbo.DelimitedSplit8K(@p_lista, ',') Contrapartes ON LN_contrapartes.contraparte = Contrapartes.Item
left join (SELECT contraparte, gestion, detalle=STUFF(
(SELECT distinct '; ' + detalle_killer AS [text()]
FROM ln_score_detalle_killer XT
WHERE XT.contraparte = T.contraparte and XT.visible = 1 and XT.gestion = T.gestion
FOR XML PATH('')), 1, 2, '')
FROM ln_score_detalle_killer T where T.visible = 1
GROUP BY contraparte,gestion) dd on (dd.contraparte = ln_contrapartes.contraparte and dd.gestion = LN_gestiones.gestion)
LEFT OUTER JOIN users as users1 ON LN_contraparte_familias.modified_by = users1.user_id
where LN_contrapartes.cliente = @p_cliente
and LN_contrapartes.activo = 1
AND LN_familias.visible = 1
AND LN_contraparte_familias.activo = 1
and LN_gestiones.desde <= GETDATE() and LN_gestiones.hasta >= GETDATE()
and LN_contrapartes.servicio_contratado = @p_servicio_contratado
order by itemNumber
--ORDER BY country.country_name, LN_familias.nombre_familia, padrones.nombre_persona
end
END
GO
Depends On
11Used By
No items found