Description
Properties
| Name | Value |
|---|---|
| ANSI Nulls ON | True |
| Quoted Identifier ON | True |
| Encrypted | False |
| Execute As | |
| Assembly |
Parameters
14| Name | Data Type | Length | Description |
|---|---|---|---|
| @p_tokenid | int | 4 | |
| @accion | varchar | 20 | |
| @p_userid | int | 4 | |
| @seccion1 | bit | 1 | |
| @seccion2 | bit | 1 | |
| @seccion3 | bit | 1 | |
| @seccion4 | bit | 1 | |
| @seccion5 | bit | 1 | |
| @seccion6 | bit | 1 | |
| @seccion7 | bit | 1 | |
| @seccion8 | bit | 1 | |
| @seccion9 | bit | 1 | |
| @seccion10 | bit | 1 | |
| @seccion11 | bit | 1 |
SQL Script
Copy
SET QUOTED_IDENTIFIER, ANSI_NULLS ON
GO
/*
select * from api_configuracion where apikey = 'WSIC39ISKHV96WHS'
*/
CREATE OR ALTER PROCEDURE dbo.apikey_secciones
@p_tokenid int,
@accion varchar(20) = 'SELECT',
@p_userid int = null,
@seccion1 bit = 0,
@seccion2 bit = 0,
@seccion3 bit = 0,
@seccion4 bit = 0,
@seccion5 bit = 0,
@seccion6 bit = 0,
@seccion7 bit = 0,
@seccion8 bit = 0,
@seccion9 bit = 0,
@seccion10 bit = 0,
@seccion11 bit = 0
AS
BEGIN
SET NOCOUNT ON;
declare @seccion1_1 bit = 0,
@seccion2_1 bit = 0,
@seccion3_1 bit = 0,
@seccion4_1 bit = 0,
@seccion5_1 bit = 0,
@seccion6_1 bit = 0,
@seccion7_1 bit = 0,
@seccion8_1 bit = 0,
@seccion9_1 bit = 0,
@seccion10_1 bit = 0,
@seccion11_1 bit = 0
declare @client_id int = null
declare @txt varchar(500) = null
declare @secciones varchar(max) = ''
declare @secciones_1 varchar(max) = ''
if (@accion = 'SELECT')
begin
select bancos_y_cheques,
comerciales,
comex,
contables,
fiscales ,
formales ,
legales ,
legales_homonimos,
relaciones,
relaciones_homonimos,
score_ic
from api_configuracion
inner join apikey on apikey.api_key = api_configuracion.apikey
where apikey.id_api_key = @p_tokenid
end
if (@accion = 'UPDATE')
begin
if (@seccion1 = 1) set @secciones = @secciones + 'bancos_y_cheques, '
if (@seccion2 = 1) set @secciones = @secciones + 'comerciales, '
if (@seccion3 = 1) set @secciones = @secciones + 'comex, '
if (@seccion4 = 1) set @secciones = @secciones + 'contables, '
if (@seccion5 = 1) set @secciones = @secciones + 'fiscales, '
if (@seccion6 = 1) set @secciones = @secciones + 'formales, '
if (@seccion7 = 1) set @secciones = @secciones + 'legales, '
if (@seccion8 = 1) set @secciones = @secciones + 'legales_homonimos, '
if (@seccion9 = 1) set @secciones = @secciones + 'relaciones, '
if (@seccion10 = 1) set @secciones = @secciones + 'relaciones_homonimos ,'
if (@seccion11 = 1) set @secciones = @secciones + 'score_ic, '
declare @apikey varchar(100) = null
select @apikey = apikey.api_key,
@client_id = client_id
from apikey
where apikey.id_api_key = @p_tokenid
if (select count(*) from api_configuracion where apikey = @apikey) = 0 -- insert
begin
if (@seccion1 = 1 or
@seccion2 = 1 or
@seccion3 = 1 or
@seccion4 = 1 or
@seccion5 = 1 or
@seccion6 = 1 or
@seccion7 = 1 or
@seccion8 = 1 or
@seccion9 = 1 or
@seccion10 = 1 or
@seccion11 = 1 )
begin
insert into api_configuracion(apikey,bancos_y_cheques,comerciales,comex,contables,fiscales,formales,legales,legales_homonimos,relaciones,relaciones_homonimos,score_ic,created)
values (@apikey,@seccion1,@seccion2,@seccion3,@seccion4,@seccion5,@seccion6,@seccion7,@seccion8,@seccion9,@seccion10,@seccion11,GETDATE())
set @txt = 'Se graban secciones en api_configuracion: ' + @secciones
insert into
trazabilidad (cliente,texto,accion,id_plataforma,user_id,created,valor_memo_new,doc_id)
values
(@client_id,@txt,'API_CONFIGURACION','API',@p_userid,getdate(),@secciones,@p_tokenid)
end
end
else
begin
select @seccion1_1 = bancos_y_cheques,
@seccion2_1 = comerciales,
@seccion3_1 = comex,
@seccion4_1 = contables,
@seccion5_1 = fiscales,
@seccion6_1 = formales,
@seccion7_1 = legales,
@seccion8_1 = legales_homonimos,
@seccion9_1 = relaciones,
@seccion10_1 = relaciones_homonimos,
@seccion11_1 = score_ic
from api_configuracion
where apikey = @apikey
-- Si hubo modificaciones, hago el update
if (@seccion1_1 != @seccion1 or
@seccion2_1 != @seccion2 or
@seccion3_1 != @seccion3 or
@seccion4_1 != @seccion4 or
@seccion5_1 != @seccion5 or
@seccion6_1 != @seccion6 or
@seccion7_1 != @seccion7 or
@seccion8_1 != @seccion8 or
@seccion9_1 != @seccion9 or
@seccion10_1 != @seccion10 or
@seccion11_1 != @seccion11)
begin
if (@seccion1_1 = 1) set @secciones_1 = @secciones_1 + 'bancos_y_cheques, '
if (@seccion2_1 = 1) set @secciones_1 = @secciones_1 + 'comerciales, '
if (@seccion3_1 = 1) set @secciones_1 = @secciones_1 + 'comex, '
if (@seccion4_1 = 1) set @secciones_1 = @secciones_1 + 'contables, '
if (@seccion5_1 = 1) set @secciones_1 = @secciones_1 + 'fiscales, '
if (@seccion6_1 = 1) set @secciones_1 = @secciones_1 + 'formales, '
if (@seccion7_1 = 1) set @secciones_1 = @secciones_1 + 'legales, '
if (@seccion8_1 = 1) set @secciones_1 = @secciones_1 + 'legales_homonimos, '
if (@seccion9_1 = 1) set @secciones_1 = @secciones_1 + 'relaciones, '
if (@seccion10_1 = 1) set @secciones_1 = @secciones_1 + 'relaciones_homonimos, '
if (@seccion11_1 = 1) set @secciones_1 = @secciones_1 + 'score_ic, '
update api_configuracion
set bancos_y_cheques = @seccion1,
comerciales = @seccion2,
comex = @seccion3,
contables = @seccion4,
fiscales = @seccion5,
formales = @seccion6,
legales = @seccion7,
legales_homonimos = @seccion8,
relaciones = @seccion9,
relaciones_homonimos = @seccion10,
score_ic = @seccion11,
modified = GETDATE()
where apikey = @apikey
if (@secciones = '') set @txt = 'Se sacan todas las secciones en api_configuracion'
else
set @txt = 'Se cambian secciones en api_configuracion: ' + @secciones
insert into
trazabilidad (cliente,texto,accion,id_plataforma,user_id,created,valor_memo_new,valor_memo_old,doc_id)
values
(@client_id,@txt,'API_CONFIGURACION','API',@p_userid,getdate(),@secciones,@secciones_1, @p_tokenid)
end
end
end
END
select * from api_configuracion where apikey = '99B59DCFLED79786'
GO
GO
/*
select * from api_configuracion where apikey = 'WSIC39ISKHV96WHS'
*/
CREATE OR ALTER PROCEDURE dbo.apikey_secciones
@p_tokenid int,
@accion varchar(20) = 'SELECT',
@p_userid int = null,
@seccion1 bit = 0,
@seccion2 bit = 0,
@seccion3 bit = 0,
@seccion4 bit = 0,
@seccion5 bit = 0,
@seccion6 bit = 0,
@seccion7 bit = 0,
@seccion8 bit = 0,
@seccion9 bit = 0,
@seccion10 bit = 0,
@seccion11 bit = 0
AS
BEGIN
SET NOCOUNT ON;
declare @seccion1_1 bit = 0,
@seccion2_1 bit = 0,
@seccion3_1 bit = 0,
@seccion4_1 bit = 0,
@seccion5_1 bit = 0,
@seccion6_1 bit = 0,
@seccion7_1 bit = 0,
@seccion8_1 bit = 0,
@seccion9_1 bit = 0,
@seccion10_1 bit = 0,
@seccion11_1 bit = 0
declare @client_id int = null
declare @txt varchar(500) = null
declare @secciones varchar(max) = ''
declare @secciones_1 varchar(max) = ''
if (@accion = 'SELECT')
begin
select bancos_y_cheques,
comerciales,
comex,
contables,
fiscales ,
formales ,
legales ,
legales_homonimos,
relaciones,
relaciones_homonimos,
score_ic
from api_configuracion
inner join apikey on apikey.api_key = api_configuracion.apikey
where apikey.id_api_key = @p_tokenid
end
if (@accion = 'UPDATE')
begin
if (@seccion1 = 1) set @secciones = @secciones + 'bancos_y_cheques, '
if (@seccion2 = 1) set @secciones = @secciones + 'comerciales, '
if (@seccion3 = 1) set @secciones = @secciones + 'comex, '
if (@seccion4 = 1) set @secciones = @secciones + 'contables, '
if (@seccion5 = 1) set @secciones = @secciones + 'fiscales, '
if (@seccion6 = 1) set @secciones = @secciones + 'formales, '
if (@seccion7 = 1) set @secciones = @secciones + 'legales, '
if (@seccion8 = 1) set @secciones = @secciones + 'legales_homonimos, '
if (@seccion9 = 1) set @secciones = @secciones + 'relaciones, '
if (@seccion10 = 1) set @secciones = @secciones + 'relaciones_homonimos ,'
if (@seccion11 = 1) set @secciones = @secciones + 'score_ic, '
declare @apikey varchar(100) = null
select @apikey = apikey.api_key,
@client_id = client_id
from apikey
where apikey.id_api_key = @p_tokenid
if (select count(*) from api_configuracion where apikey = @apikey) = 0 -- insert
begin
if (@seccion1 = 1 or
@seccion2 = 1 or
@seccion3 = 1 or
@seccion4 = 1 or
@seccion5 = 1 or
@seccion6 = 1 or
@seccion7 = 1 or
@seccion8 = 1 or
@seccion9 = 1 or
@seccion10 = 1 or
@seccion11 = 1 )
begin
insert into api_configuracion(apikey,bancos_y_cheques,comerciales,comex,contables,fiscales,formales,legales,legales_homonimos,relaciones,relaciones_homonimos,score_ic,created)
values (@apikey,@seccion1,@seccion2,@seccion3,@seccion4,@seccion5,@seccion6,@seccion7,@seccion8,@seccion9,@seccion10,@seccion11,GETDATE())
set @txt = 'Se graban secciones en api_configuracion: ' + @secciones
insert into
trazabilidad (cliente,texto,accion,id_plataforma,user_id,created,valor_memo_new,doc_id)
values
(@client_id,@txt,'API_CONFIGURACION','API',@p_userid,getdate(),@secciones,@p_tokenid)
end
end
else
begin
select @seccion1_1 = bancos_y_cheques,
@seccion2_1 = comerciales,
@seccion3_1 = comex,
@seccion4_1 = contables,
@seccion5_1 = fiscales,
@seccion6_1 = formales,
@seccion7_1 = legales,
@seccion8_1 = legales_homonimos,
@seccion9_1 = relaciones,
@seccion10_1 = relaciones_homonimos,
@seccion11_1 = score_ic
from api_configuracion
where apikey = @apikey
-- Si hubo modificaciones, hago el update
if (@seccion1_1 != @seccion1 or
@seccion2_1 != @seccion2 or
@seccion3_1 != @seccion3 or
@seccion4_1 != @seccion4 or
@seccion5_1 != @seccion5 or
@seccion6_1 != @seccion6 or
@seccion7_1 != @seccion7 or
@seccion8_1 != @seccion8 or
@seccion9_1 != @seccion9 or
@seccion10_1 != @seccion10 or
@seccion11_1 != @seccion11)
begin
if (@seccion1_1 = 1) set @secciones_1 = @secciones_1 + 'bancos_y_cheques, '
if (@seccion2_1 = 1) set @secciones_1 = @secciones_1 + 'comerciales, '
if (@seccion3_1 = 1) set @secciones_1 = @secciones_1 + 'comex, '
if (@seccion4_1 = 1) set @secciones_1 = @secciones_1 + 'contables, '
if (@seccion5_1 = 1) set @secciones_1 = @secciones_1 + 'fiscales, '
if (@seccion6_1 = 1) set @secciones_1 = @secciones_1 + 'formales, '
if (@seccion7_1 = 1) set @secciones_1 = @secciones_1 + 'legales, '
if (@seccion8_1 = 1) set @secciones_1 = @secciones_1 + 'legales_homonimos, '
if (@seccion9_1 = 1) set @secciones_1 = @secciones_1 + 'relaciones, '
if (@seccion10_1 = 1) set @secciones_1 = @secciones_1 + 'relaciones_homonimos, '
if (@seccion11_1 = 1) set @secciones_1 = @secciones_1 + 'score_ic, '
update api_configuracion
set bancos_y_cheques = @seccion1,
comerciales = @seccion2,
comex = @seccion3,
contables = @seccion4,
fiscales = @seccion5,
formales = @seccion6,
legales = @seccion7,
legales_homonimos = @seccion8,
relaciones = @seccion9,
relaciones_homonimos = @seccion10,
score_ic = @seccion11,
modified = GETDATE()
where apikey = @apikey
if (@secciones = '') set @txt = 'Se sacan todas las secciones en api_configuracion'
else
set @txt = 'Se cambian secciones en api_configuracion: ' + @secciones
insert into
trazabilidad (cliente,texto,accion,id_plataforma,user_id,created,valor_memo_new,valor_memo_old,doc_id)
values
(@client_id,@txt,'API_CONFIGURACION','API',@p_userid,getdate(),@secciones,@secciones_1, @p_tokenid)
end
end
end
END
select * from api_configuracion where apikey = '99B59DCFLED79786'
GO
Depends On
2Used By
No items found