Description
Properties
| Name | Value |
|---|---|
| ANSI Nulls ON | True |
| Quoted Identifier ON | True |
| Encrypted | False |
| Execute As | |
| Assembly |
Parameters
2| Name | Data Type | Length | Description |
|---|---|---|---|
| @apikey | varchar | 100 | |
| @fecha | datetime | 8 |
SQL Script
Copy
SET QUOTED_IDENTIFIER, ANSI_NULLS ON
GO
/*
select * from apikey where producto >= 106
exec API_consumos_detalle 'PWSAPIKEY', '2023-09-01'
exec API_consumos_detalle 'PREAPIKEY', '2023-10-20'
exec API_consumos_detalle 'PRFAPIKEY', '2023-10-20'
*/
CREATE OR ALTER PROCEDURE dbo.API_consumos_detalle
@apikey varchar(100),
@fecha datetime
AS
BEGIN
SET NOCOUNT ON;
declare @ptipo_api char(1) = ''
declare @pUserKey int = 0
declare @pProdKey int = 0
declare @firstMonthday datetime
declare @lastMonthday datetime
set @firstMonthday = DATEADD(DAY, 1, EOMONTH(@fecha, -1))
set @lastMonthday = EOMONTH(@fecha)
SET @lastMonthday = CONVERT(DATETIME, CONVERT(varchar(11),@lastMonthday, 111 ) + ' 23:59:59', 111)
declare @restultado table (fecha date, consultado varchar(20), otro varchar(max))
DECLARE C_api_consumo CURSOR FOR
select distinct apikey.tipo_api, apikey.user_id,apikey.producto
from apikey
where apikey.api_key = @apikey
OPEN C_api_consumo
FETCH NEXT FROM C_api_consumo INTO @ptipo_api,@pUserKey,@pProdKey
WHILE @@fetch_status = 0
BEGIN
if (@ptipo_api!='P')
begin
insert into @restultado
select created, cuit_consultado,
iif ((select count(*) from padrones where padrones.identificacion = cuit_consultado
and padrones.habilitado = '1') = 1,
(select nombre_persona from padrones where padrones.identificacion = cuit_consultado
and padrones.habilitado = '1'),
null) as nombre
from usuarios_consumos
where user_id= @pUserKey and id_producto=@pProdKey
and convert(date,created) between @firstMonthday and @lastMonthday
end
else
begin
if (@pProdKey = 106) -- API A PROVEEDOR - WORLDSYS
begin
insert into @restultado
select distinct convert(date,created), DocumentoBuscado, NombreBuscado from LN_Fidecheck_ws
where StatusCode = 200 and convert(date,created) between @firstMonthday and @lastMonthday
end
if (@pProdKey = 107) -- API A PROVEEDOR - RENAPER
begin
insert into @restultado
select created, dni, sexo from RENAPER_INFO
where codigoError = 99 and convert(date,created) between @firstMonthday and @lastMonthday
end
if (@pProdKey = 108) -- API A PROVEEDOR - RENAPER FACE MATCH
begin
insert into @restultado
select created, dni, sexo from RENAPER_FACE_INFO
where codigo_http = 200 and convert(date,created) between @firstMonthday and @lastMonthday
end
end
FETCH NEXT FROM C_api_consumo INTO @ptipo_api,@pUserKey,@pProdKey
END
CLOSE C_api_consumo
DEALLOCATE C_api_consumo
select fecha,consultado,otro from @restultado
order by fecha
END
GO
GO
/*
select * from apikey where producto >= 106
exec API_consumos_detalle 'PWSAPIKEY', '2023-09-01'
exec API_consumos_detalle 'PREAPIKEY', '2023-10-20'
exec API_consumos_detalle 'PRFAPIKEY', '2023-10-20'
*/
CREATE OR ALTER PROCEDURE dbo.API_consumos_detalle
@apikey varchar(100),
@fecha datetime
AS
BEGIN
SET NOCOUNT ON;
declare @ptipo_api char(1) = ''
declare @pUserKey int = 0
declare @pProdKey int = 0
declare @firstMonthday datetime
declare @lastMonthday datetime
set @firstMonthday = DATEADD(DAY, 1, EOMONTH(@fecha, -1))
set @lastMonthday = EOMONTH(@fecha)
SET @lastMonthday = CONVERT(DATETIME, CONVERT(varchar(11),@lastMonthday, 111 ) + ' 23:59:59', 111)
declare @restultado table (fecha date, consultado varchar(20), otro varchar(max))
DECLARE C_api_consumo CURSOR FOR
select distinct apikey.tipo_api, apikey.user_id,apikey.producto
from apikey
where apikey.api_key = @apikey
OPEN C_api_consumo
FETCH NEXT FROM C_api_consumo INTO @ptipo_api,@pUserKey,@pProdKey
WHILE @@fetch_status = 0
BEGIN
if (@ptipo_api!='P')
begin
insert into @restultado
select created, cuit_consultado,
iif ((select count(*) from padrones where padrones.identificacion = cuit_consultado
and padrones.habilitado = '1') = 1,
(select nombre_persona from padrones where padrones.identificacion = cuit_consultado
and padrones.habilitado = '1'),
null) as nombre
from usuarios_consumos
where user_id= @pUserKey and id_producto=@pProdKey
and convert(date,created) between @firstMonthday and @lastMonthday
end
else
begin
if (@pProdKey = 106) -- API A PROVEEDOR - WORLDSYS
begin
insert into @restultado
select distinct convert(date,created), DocumentoBuscado, NombreBuscado from LN_Fidecheck_ws
where StatusCode = 200 and convert(date,created) between @firstMonthday and @lastMonthday
end
if (@pProdKey = 107) -- API A PROVEEDOR - RENAPER
begin
insert into @restultado
select created, dni, sexo from RENAPER_INFO
where codigoError = 99 and convert(date,created) between @firstMonthday and @lastMonthday
end
if (@pProdKey = 108) -- API A PROVEEDOR - RENAPER FACE MATCH
begin
insert into @restultado
select created, dni, sexo from RENAPER_FACE_INFO
where codigo_http = 200 and convert(date,created) between @firstMonthday and @lastMonthday
end
end
FETCH NEXT FROM C_api_consumo INTO @ptipo_api,@pUserKey,@pProdKey
END
CLOSE C_api_consumo
DEALLOCATE C_api_consumo
select fecha,consultado,otro from @restultado
order by fecha
END
GO
Depends On
6Used By
No items found