Description
Properties
| Name | Value |
|---|---|
| ANSI Nulls ON | True |
| Quoted Identifier ON | True |
| Encrypted | False |
| Execute As | |
| Assembly |
Parameters
2| Name | Data Type | Length | Description |
|---|---|---|---|
| @cliente | int | 4 | |
| @top | tinyint | 1 |
SQL Script
Copy
SET QUOTED_IDENTIFIER, ANSI_NULLS ON
GO
--select * from padrones where identificacion in ('30708886633','30581993834','33708384599','30693697510','30708886633')
--update padrones set nombre_persona='PATAGONIA HOME GROUP SOCIEDAD SIMPLE' where id_padron=204086371
--select * from ln_contrapartes where id_padron in (204083140,203820875)
/*
select * from mis_aportes_control order by nombre_cliente,nombre_contraparte,nombre_empleado asc
-- truncate table mis_aportes_control
exec mis_aportes_select 1659303046,3
exec mis_aportes_select 2046807993,3
1659303046,2046807993
*/
CREATE OR ALTER PROCEDURE dbo.mis_aportes_select
@cliente int,
@top tinyint
AS
BEGIN
SET NOCOUNT ON;
declare @identificacion varchar(30)
declare @nombreCliente varchar(150)
select @nombreCliente = padrones.nombre_persona from clientes inner join padrones on clientes.numero=padrones.identificacion where cliente = @cliente
DECLARE aportesC Cursor
FOR
select DISTINCT identificacion from ln_contrapartes inner join padrones PCONTRA ON LN_contrapartes.id_padron=PCONTRA.id_padron where cliente in (@cliente) and activo=1 and PCONTRA.identificador in ('CUIT','CUIL','CDI') and PCONTRA.habilitado=1
Open aportesC
Fetch NEXT FROM aportesC INTO @identificacion
While (@@FETCH_STATUS <> -1)
BEGIN
BEGIN TRY
/*
insert into mis_aportes_control (cliente,nombre_cliente,cuit_contraparte,nombre_contraparte,cuil_empleado,nombre_empleado)
values (cliente,nombre_cliente,cuit_contraparte,nombre_contraparte,cuil_empleado,nombre_empleado)
*/
insert into mis_aportes_control (cliente,nombre_cliente,cuit_contraparte,nombre_contraparte,cuil_empleado,nombre_empleado)
SELECT TOP (@top) @cliente,@nombreCliente,EMPLEADOS.CUIT,PC.nombre_persona, EMPLEADOS.cuil,PE.nombre_persona FROM EMPLEADOS inner join padrones PE on (empleados.cuil = PE.identificacion and PE.identificador in ('CUIT','CUIL','CDI') and PE.habilitado=1 and
EMPLEADOS.periodo=2203)
inner join padrones PC on (PC.identificacion=EMPLEADOs.cuit and PE.identificador in ('CUIT','CUIL','CDI') and PE.habilitado=1 and
EMPLEADOS.periodo=2203)
where PC.identificacion in (@identificacion)
END TRY
BEGIN CATCH
END CATCH
Fetch NEXT FROM aportesC INTO @identificacion
END
CLOSE aportesC
DEALLOCATE aportesC
END
GO
GO
--select * from padrones where identificacion in ('30708886633','30581993834','33708384599','30693697510','30708886633')
--update padrones set nombre_persona='PATAGONIA HOME GROUP SOCIEDAD SIMPLE' where id_padron=204086371
--select * from ln_contrapartes where id_padron in (204083140,203820875)
/*
select * from mis_aportes_control order by nombre_cliente,nombre_contraparte,nombre_empleado asc
-- truncate table mis_aportes_control
exec mis_aportes_select 1659303046,3
exec mis_aportes_select 2046807993,3
1659303046,2046807993
*/
CREATE OR ALTER PROCEDURE dbo.mis_aportes_select
@cliente int,
@top tinyint
AS
BEGIN
SET NOCOUNT ON;
declare @identificacion varchar(30)
declare @nombreCliente varchar(150)
select @nombreCliente = padrones.nombre_persona from clientes inner join padrones on clientes.numero=padrones.identificacion where cliente = @cliente
DECLARE aportesC Cursor
FOR
select DISTINCT identificacion from ln_contrapartes inner join padrones PCONTRA ON LN_contrapartes.id_padron=PCONTRA.id_padron where cliente in (@cliente) and activo=1 and PCONTRA.identificador in ('CUIT','CUIL','CDI') and PCONTRA.habilitado=1
Open aportesC
Fetch NEXT FROM aportesC INTO @identificacion
While (@@FETCH_STATUS <> -1)
BEGIN
BEGIN TRY
/*
insert into mis_aportes_control (cliente,nombre_cliente,cuit_contraparte,nombre_contraparte,cuil_empleado,nombre_empleado)
values (cliente,nombre_cliente,cuit_contraparte,nombre_contraparte,cuil_empleado,nombre_empleado)
*/
insert into mis_aportes_control (cliente,nombre_cliente,cuit_contraparte,nombre_contraparte,cuil_empleado,nombre_empleado)
SELECT TOP (@top) @cliente,@nombreCliente,EMPLEADOS.CUIT,PC.nombre_persona, EMPLEADOS.cuil,PE.nombre_persona FROM EMPLEADOS inner join padrones PE on (empleados.cuil = PE.identificacion and PE.identificador in ('CUIT','CUIL','CDI') and PE.habilitado=1 and
EMPLEADOS.periodo=2203)
inner join padrones PC on (PC.identificacion=EMPLEADOs.cuit and PE.identificador in ('CUIT','CUIL','CDI') and PE.habilitado=1 and
EMPLEADOS.periodo=2203)
where PC.identificacion in (@identificacion)
END TRY
BEGIN CATCH
END CATCH
Fetch NEXT FROM aportesC INTO @identificacion
END
CLOSE aportesC
DEALLOCATE aportesC
END
GO
Depends On
4Used By
No items found