Description
Properties
| Name | Value |
|---|---|
| ANSI Nulls ON | True |
| Quoted Identifier ON | True |
| Encrypted | False |
| Execute As | |
| Assembly |
Parameters
8| Name | Data Type | Length | Description |
|---|---|---|---|
| @id_padron | int | 4 | |
| @nombre_persona | varchar | 200 | |
| @tipo_persona | varchar | 1 | |
| @sexo | varchar | 1 | |
| @habilitado | bit | 1 | |
| @identificador | varchar | 10 | |
| @numero | varchar | 50 | |
| @contraparte | int | 4 |
SQL Script
Copy
SET QUOTED_IDENTIFIER, ANSI_NULLS ON
GO
-- =============================================
-- Author: <Author,,Name>
-- Create date: <Create Date,,>
-- Description: <Description,,>
-- =============================================
/*
select * from padrones where id_padron = 209962613
exec backend_update_id_padron '209962613','DIEGO VILLARROEL N','F','M',1
*/
CREATE OR ALTER PROCEDURE dbo.backend_update_id_padron
-- Add the parameters for the stored procedure here
@id_padron int,
@nombre_persona varchar(200),
@tipo_persona varchar(1),
@sexo varchar(1),
@habilitado bit,
@identificador varchar(10) = NULL,
@numero varchar(50) = NULL,
@contraparte 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 (@identificador IS NULL AND @numero IS NULL AND @contraparte IS NULL)
begin
UPDATE padrones SET
nombre_persona = UPPER(@nombre_persona),
tipo_persona = UPPER(@tipo_persona),
sexo = UPPER(@sexo),
habilitado = @habilitado,
ismodified = GETDATE()
WHERE id_padron = @id_padron
return
end
else begin
declare @padron int = NULL
declare @prev_ident varchar(10) = NULL
declare @prev_num varchar(50) = NULL
select @padron = id_padron
from padrones
where identificador = @identificador
and numero = @numero
and habilitado = 1
and id_padron <> @id_padron
if (@contraparte is not null)
select @prev_ident = padrones.identificador,
@prev_num = padrones.numero
from padrones inner join LN_contrapartes on padrones.id_padron = LN_contrapartes.id_padron
where LN_contrapartes.contraparte = @contraparte
/*update LN_contrapartes set id_padron = @padron where contraparte = @contraparte
select @prev_ident = identificador, @prev_num = numero from padrones where id_padron = @id_padron
update padrones set habilitado = 0 where id_padron = @id_padron*/
if (@padron is null) begin
DECLARE @cc varchar(2)
DECLARE @pre_clave varchar(4) = NULL
DECLARE @cuerpo_clave varchar(40) = NULL
DECLARE @suf_clave varchar(4) = NULL
select @cc = country_code from identificadores where identificador = @identificador
SET @numero = REPLACE(@numero, '/', '')
SET @numero = REPLACE(@numero, '-', '')
SET @numero = REPLACE(@numero, '.', '')
SET @numero = REPLACE(@numero, ',', '')
if ( @cc = 'AR' AND (@identificador = 'CUIT' OR @identificador = 'CUIL') AND LEN(@numero) = 11 ) begin
SET @pre_clave = SUBSTRING(@numero,1,2)
SET @cuerpo_clave = SUBSTRING(@numero,3,8)
SET @suf_clave = SUBSTRING(@numero,11,1)
end else begin
SET @cuerpo_clave = @numero
end
UPDATE padrones SET
identificador = @identificador,
numero = @numero,
identificacion = @numero,
nombre_persona = UPPER(@nombre_persona),
tipo_persona = UPPER(@tipo_persona),
sexo = UPPER(@sexo),
pre_clave = @pre_clave,
cuerpo_clave = @cuerpo_clave,
suf_clave = @suf_clave,
habilitado = @habilitado,
ismodified = GETDATE()
WHERE id_padron = @id_padron
end
-- actualización de informes en blue
if (@contraparte is not null AND @prev_ident is not null and @prev_num is not null) begin
declare @informe int = null
select @informe = informes.informe
from informes
inner join LN_demo on informes.informe = LN_demo.informe
inner join LN_gestiones on (LN_demo.contraparte = LN_gestiones.contraparte
and LN_demo.gestion = LN_gestiones.gestion)
where LN_demo.contraparte = @contraparte
and LN_gestiones.desde < GETDATE()
and LN_gestiones.hasta > GETDATE()
and informes.identificador = @prev_ident
and informes.numero = @prev_num
if (@informe is not null) begin
update informes set identificador = @identificador,
numero = @numero
where informe = @informe
update informes set identificador = @identificador,
numero = @numero
where informe_padre = @informe
end
end
-- actualización de fidecheck
if (@prev_ident is not null and @prev_num is not null) begin
update LN_demo_fidecheck set tax_id = @numero where tax_id = @prev_num
end
end
END
GO
GO
-- =============================================
-- Author: <Author,,Name>
-- Create date: <Create Date,,>
-- Description: <Description,,>
-- =============================================
/*
select * from padrones where id_padron = 209962613
exec backend_update_id_padron '209962613','DIEGO VILLARROEL N','F','M',1
*/
CREATE OR ALTER PROCEDURE dbo.backend_update_id_padron
-- Add the parameters for the stored procedure here
@id_padron int,
@nombre_persona varchar(200),
@tipo_persona varchar(1),
@sexo varchar(1),
@habilitado bit,
@identificador varchar(10) = NULL,
@numero varchar(50) = NULL,
@contraparte 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 (@identificador IS NULL AND @numero IS NULL AND @contraparte IS NULL)
begin
UPDATE padrones SET
nombre_persona = UPPER(@nombre_persona),
tipo_persona = UPPER(@tipo_persona),
sexo = UPPER(@sexo),
habilitado = @habilitado,
ismodified = GETDATE()
WHERE id_padron = @id_padron
return
end
else begin
declare @padron int = NULL
declare @prev_ident varchar(10) = NULL
declare @prev_num varchar(50) = NULL
select @padron = id_padron
from padrones
where identificador = @identificador
and numero = @numero
and habilitado = 1
and id_padron <> @id_padron
if (@contraparte is not null)
select @prev_ident = padrones.identificador,
@prev_num = padrones.numero
from padrones inner join LN_contrapartes on padrones.id_padron = LN_contrapartes.id_padron
where LN_contrapartes.contraparte = @contraparte
/*update LN_contrapartes set id_padron = @padron where contraparte = @contraparte
select @prev_ident = identificador, @prev_num = numero from padrones where id_padron = @id_padron
update padrones set habilitado = 0 where id_padron = @id_padron*/
if (@padron is null) begin
DECLARE @cc varchar(2)
DECLARE @pre_clave varchar(4) = NULL
DECLARE @cuerpo_clave varchar(40) = NULL
DECLARE @suf_clave varchar(4) = NULL
select @cc = country_code from identificadores where identificador = @identificador
SET @numero = REPLACE(@numero, '/', '')
SET @numero = REPLACE(@numero, '-', '')
SET @numero = REPLACE(@numero, '.', '')
SET @numero = REPLACE(@numero, ',', '')
if ( @cc = 'AR' AND (@identificador = 'CUIT' OR @identificador = 'CUIL') AND LEN(@numero) = 11 ) begin
SET @pre_clave = SUBSTRING(@numero,1,2)
SET @cuerpo_clave = SUBSTRING(@numero,3,8)
SET @suf_clave = SUBSTRING(@numero,11,1)
end else begin
SET @cuerpo_clave = @numero
end
UPDATE padrones SET
identificador = @identificador,
numero = @numero,
identificacion = @numero,
nombre_persona = UPPER(@nombre_persona),
tipo_persona = UPPER(@tipo_persona),
sexo = UPPER(@sexo),
pre_clave = @pre_clave,
cuerpo_clave = @cuerpo_clave,
suf_clave = @suf_clave,
habilitado = @habilitado,
ismodified = GETDATE()
WHERE id_padron = @id_padron
end
-- actualización de informes en blue
if (@contraparte is not null AND @prev_ident is not null and @prev_num is not null) begin
declare @informe int = null
select @informe = informes.informe
from informes
inner join LN_demo on informes.informe = LN_demo.informe
inner join LN_gestiones on (LN_demo.contraparte = LN_gestiones.contraparte
and LN_demo.gestion = LN_gestiones.gestion)
where LN_demo.contraparte = @contraparte
and LN_gestiones.desde < GETDATE()
and LN_gestiones.hasta > GETDATE()
and informes.identificador = @prev_ident
and informes.numero = @prev_num
if (@informe is not null) begin
update informes set identificador = @identificador,
numero = @numero
where informe = @informe
update informes set identificador = @identificador,
numero = @numero
where informe_padre = @informe
end
end
-- actualización de fidecheck
if (@prev_ident is not null and @prev_num is not null) begin
update LN_demo_fidecheck set tax_id = @numero where tax_id = @prev_num
end
end
END
GO
Depends On
6Used By
No items found