Description
Properties
| Name | Value |
|---|---|
| ANSI Nulls ON | True |
| Quoted Identifier ON | True |
| Encrypted | False |
| Execute As | |
| Assembly |
Parameters
2| Name | Data Type | Length | Description |
|---|---|---|---|
| @contraparte | int | 4 | |
| @score_fide | decimal | 9 |
SQL Script
Copy
SET QUOTED_IDENTIFIER, ANSI_NULLS ON
GO
/*
-- =============================================
-- Author: <María Inés Soria>
-- Create date: <30/09/2019>
-- Description: Cálculo de Score de datos aportados por el cliente
-- =============================================
DECLARE @score_datos decimal(10,2)
EXEC [dbo].[LN_score_datos] 43879, @score_datos output
select @score_datos as score_datos
select * from ln_contraparte_datos_aportados
*/
CREATE OR ALTER PROCEDURE dbo.LN_score_fidecheck_ant
@contraparte int,
@score_fide decimal(10,2) = null output
AS
BEGIN
SET NOCOUNT ON;
declare @detalle varchar(max) = null
declare @cliente int = (select cliente from ln_contrapartes where contraparte = @contraparte)
declare @score_final decimal(10,2) = null
IF (select count(*) from LN_demo_fidecheck
where contraparte = @contraparte and visible = 1
and fidecheck = 'P') > 0 begin
SET @score_final = -100
if (@detalle is null)
set @detalle = 'FIDECHECK POSITIVE'
else
set @detalle = @detalle + '; FIDECHECK POSITIVE'
end
ELSE
IF (select count(*) from LN_demo_fidecheck
where contraparte = @contraparte and visible = 1
and fidecheck = 'R') > 0 begin
SET @score_final = -100
if (@detalle is null)
set @detalle = 'FIDECHECK RELATED'
else
set @detalle = @detalle + '; FIDECHECK RELATED'
end
ELSE begin
IF (select count(*) from LN_demo_fidecheck
where contraparte = @contraparte and visible = 1
and fidecheck = 'N') > 0
SET @score_final = 100
end
-- Detalle Killers
declare @gestion int = (select gestion
from LN_gestiones
where contraparte = @contraparte
AND LN_gestiones.desde <= GETDATE()
AND LN_gestiones.hasta >= GETDATE())
declare @indicador int = (select indicador
from ln_indicadores
inner join LN_productos on ln_productos.producto = LN_indicadores.producto
where clave_indicador = 'SCORE_FIDECHECK')
if exists (select * From ln_score_detalle_killer
where contraparte = @contraparte
and gestion = @gestion
and indicador = @indicador
and detalle_killer != isnull(@detalle,'')
and visible = 1)
UPDATE LN_score_detalle_killer
set visible = 0, modified = getdate()
where contraparte = @contraparte
and gestion = @gestion
and indicador = @indicador
if (@detalle is not null)
begin
if not exists (select * From ln_score_detalle_killer
where contraparte = @contraparte
and gestion = @gestion
and indicador = @indicador
and detalle_killer = isnull(@detalle,'')
and visible = 1)
insert into ln_score_detalle_killer
(contraparte, gestion, indicador, detalle_killer, visible, created)
values (@contraparte, @gestion, @indicador, @detalle, 1, getdate())
end
set @score_fide = @score_final
END
GO
GO
/*
-- =============================================
-- Author: <María Inés Soria>
-- Create date: <30/09/2019>
-- Description: Cálculo de Score de datos aportados por el cliente
-- =============================================
DECLARE @score_datos decimal(10,2)
EXEC [dbo].[LN_score_datos] 43879, @score_datos output
select @score_datos as score_datos
select * from ln_contraparte_datos_aportados
*/
CREATE OR ALTER PROCEDURE dbo.LN_score_fidecheck_ant
@contraparte int,
@score_fide decimal(10,2) = null output
AS
BEGIN
SET NOCOUNT ON;
declare @detalle varchar(max) = null
declare @cliente int = (select cliente from ln_contrapartes where contraparte = @contraparte)
declare @score_final decimal(10,2) = null
IF (select count(*) from LN_demo_fidecheck
where contraparte = @contraparte and visible = 1
and fidecheck = 'P') > 0 begin
SET @score_final = -100
if (@detalle is null)
set @detalle = 'FIDECHECK POSITIVE'
else
set @detalle = @detalle + '; FIDECHECK POSITIVE'
end
ELSE
IF (select count(*) from LN_demo_fidecheck
where contraparte = @contraparte and visible = 1
and fidecheck = 'R') > 0 begin
SET @score_final = -100
if (@detalle is null)
set @detalle = 'FIDECHECK RELATED'
else
set @detalle = @detalle + '; FIDECHECK RELATED'
end
ELSE begin
IF (select count(*) from LN_demo_fidecheck
where contraparte = @contraparte and visible = 1
and fidecheck = 'N') > 0
SET @score_final = 100
end
-- Detalle Killers
declare @gestion int = (select gestion
from LN_gestiones
where contraparte = @contraparte
AND LN_gestiones.desde <= GETDATE()
AND LN_gestiones.hasta >= GETDATE())
declare @indicador int = (select indicador
from ln_indicadores
inner join LN_productos on ln_productos.producto = LN_indicadores.producto
where clave_indicador = 'SCORE_FIDECHECK')
if exists (select * From ln_score_detalle_killer
where contraparte = @contraparte
and gestion = @gestion
and indicador = @indicador
and detalle_killer != isnull(@detalle,'')
and visible = 1)
UPDATE LN_score_detalle_killer
set visible = 0, modified = getdate()
where contraparte = @contraparte
and gestion = @gestion
and indicador = @indicador
if (@detalle is not null)
begin
if not exists (select * From ln_score_detalle_killer
where contraparte = @contraparte
and gestion = @gestion
and indicador = @indicador
and detalle_killer = isnull(@detalle,'')
and visible = 1)
insert into ln_score_detalle_killer
(contraparte, gestion, indicador, detalle_killer, visible, created)
values (@contraparte, @gestion, @indicador, @detalle, 1, getdate())
end
set @score_fide = @score_final
END
GO
Depends On
6Used By
No items found