Description
Properties
| Name | Value |
|---|---|
| ANSI Nulls ON | True |
| Quoted Identifier ON | True |
| Encrypted | False |
| Execute As | |
| Assembly |
Parameters
6| Name | Data Type | Length | Description |
|---|---|---|---|
| @p_cuit | varchar | 30 | |
| @p_cuit_asociado | varchar | 30 | |
| @p_fecha_relacion | varchar | 50 | |
| @p_fecha_vencimiento | varchar | 50 | |
| @p_tipo_relacion | varchar | 200 | |
| @p_sub_tipo_relacion | varchar | 200 |
SQL Script
Copy
SET QUOTED_IDENTIFIER, ANSI_NULLS ON
GO
-- =============================================
-- Author: <Samuel Gonzalez>
-- Create date: <27 dic 2017>
-- Description: <Insertar relaciones/socios obtenidos de afip>
-- =============================================
CREATE OR ALTER PROCEDURE dbo.insertar_relaciones_afip
-- Add the parameters for the stored procedure here
@p_cuit varchar(30),
@p_cuit_asociado varchar(30),
@p_fecha_relacion varchar(50),
@p_fecha_vencimiento varchar(50),
@p_tipo_relacion varchar(200),
@p_sub_tipo_relacion varchar(200)
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
begin try
if ((select COUNT(*) from relaciones r
inner join tipos_relaciones tr on (r.id_tipo_relacion = tr.id_tipo_relacion)
inner join tipos_subrelaciones sr on (r.id_tipo_subrelacion = sr.id_subrelacion)
where (r.cuita = @p_cuit) and (r.cuitb = @p_cuit_asociado) and (tr.relacion = @p_tipo_relacion) and (sr.subrelacion = @p_sub_tipo_relacion)) = 0)
begin
declare @id_tipo_relacion int = (select top 1 id_tipo_relacion from tipos_relaciones t where (t.relacion = @p_tipo_relacion))
if (@id_tipo_relacion is null)
begin
insert into tipos_relaciones (relacion) values (@p_tipo_relacion)
set @id_tipo_relacion = SCOPE_IDENTITY()
end
declare @id_tipo_subrelacion int = (select top 1 id_subrelacion from tipos_subrelaciones t where (t.subrelacion = @p_sub_tipo_relacion))
if (@id_tipo_subrelacion is null)
begin
insert into tipos_subrelaciones (subrelacion) values (@p_sub_tipo_relacion)
set @id_tipo_subrelacion = SCOPE_IDENTITY()
end
insert into relaciones
(cuita, cuitb, fecha_relacion, fecha_vencimiento, id_tipo_relacion, id_tipo_subrelacion, origen_del_dato, created) values
(@p_cuit, @p_cuit_asociado, @p_fecha_relacion, @p_fecha_vencimiento, @id_tipo_relacion, @id_tipo_subrelacion, 'AFIP', GETDATE())
select 'ok' as ok
end
end try
begin catch
select ERROR_MESSAGE() as error
end catch
END
GO
GO
-- =============================================
-- Author: <Samuel Gonzalez>
-- Create date: <27 dic 2017>
-- Description: <Insertar relaciones/socios obtenidos de afip>
-- =============================================
CREATE OR ALTER PROCEDURE dbo.insertar_relaciones_afip
-- Add the parameters for the stored procedure here
@p_cuit varchar(30),
@p_cuit_asociado varchar(30),
@p_fecha_relacion varchar(50),
@p_fecha_vencimiento varchar(50),
@p_tipo_relacion varchar(200),
@p_sub_tipo_relacion varchar(200)
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
begin try
if ((select COUNT(*) from relaciones r
inner join tipos_relaciones tr on (r.id_tipo_relacion = tr.id_tipo_relacion)
inner join tipos_subrelaciones sr on (r.id_tipo_subrelacion = sr.id_subrelacion)
where (r.cuita = @p_cuit) and (r.cuitb = @p_cuit_asociado) and (tr.relacion = @p_tipo_relacion) and (sr.subrelacion = @p_sub_tipo_relacion)) = 0)
begin
declare @id_tipo_relacion int = (select top 1 id_tipo_relacion from tipos_relaciones t where (t.relacion = @p_tipo_relacion))
if (@id_tipo_relacion is null)
begin
insert into tipos_relaciones (relacion) values (@p_tipo_relacion)
set @id_tipo_relacion = SCOPE_IDENTITY()
end
declare @id_tipo_subrelacion int = (select top 1 id_subrelacion from tipos_subrelaciones t where (t.subrelacion = @p_sub_tipo_relacion))
if (@id_tipo_subrelacion is null)
begin
insert into tipos_subrelaciones (subrelacion) values (@p_sub_tipo_relacion)
set @id_tipo_subrelacion = SCOPE_IDENTITY()
end
insert into relaciones
(cuita, cuitb, fecha_relacion, fecha_vencimiento, id_tipo_relacion, id_tipo_subrelacion, origen_del_dato, created) values
(@p_cuit, @p_cuit_asociado, @p_fecha_relacion, @p_fecha_vencimiento, @id_tipo_relacion, @id_tipo_subrelacion, 'AFIP', GETDATE())
select 'ok' as ok
end
end try
begin catch
select ERROR_MESSAGE() as error
end catch
END
GO
Depends On
3Used By
No items found