Description
Properties
| Name | Value |
|---|---|
| ANSI Nulls ON | True |
| Quoted Identifier ON | True |
| Encrypted | False |
| Execute As | |
| Assembly |
SQL Script
Copy
SET QUOTED_IDENTIFIER, ANSI_NULLS ON
GO
--exec [balances_res_resinv]
CREATE OR ALTER PROCEDURE dbo.balances_res_resinv
AS
BEGIN
SET NOCOUNT ON;
declare @id int
declare @fecha date
declare @res_gasfin decimal(16,2)
declare @res_resinv decimal(16,2)
declare @res_resfin decimal(16,2)
declare @cant int = 0
drop table tabla_res_gasfin
select distinct fecha_balance, idifx, convert(decimal(16,2),res_gasfin) as res_gasfin,
convert(decimal(16,2),res_resinv) as res_resinv,
convert(decimal(16,2),res_resfin) as res_resfin
into tabla_res_gasfin
from BALANCES_COMPLETO_20170831_0 a
where (convert(decimal(16,2),res_gasfin) != 0.00 or convert(decimal(16,2),res_resinv) != 0.00 or convert(decimal(16,2),res_resfin) != 0.00 )
and usuario not like 'GASFIN-%'
--and fecha_balance >= '1999-01-01'
DECLARE bn CURSOR
FOR
select fecha_balance, convert(int,idifx), res_gasfin, res_resinv, res_resfin
from tabla_res_gasfin
order by fecha_balance desc
OPEN bn
Fetch next from bn INTO @fecha, @id, @res_gasfin, @res_resinv, @res_resfin
WHILE (@@FETCH_STATUS <> -1 )
BEGIN
set @cant = @cant + 1
update balances_contables
set res_gasfin = 0 - @res_gasfin - @res_resfin - @res_resinv,
res_resfin = 0
where idifx = @id
and created_by is null -- para que no toque los que modificaron en el sql a mano
and (modified_by is null or modified_by = 0)
update balances_contables
set ganancia = (isnull(res_vtanet,0)
- isnull(res_cosmer,0)
- isnull(res_gascom,0)
- isnull(res_gasadm,0)
- isnull(res_gasfin,0)
+ isnull(res_otrosing,0)
- isnull(res_otrosegr,0)
+ isnull(res_resfin,0)
- isnull(res_iva,0))
where idifx = @id
update balances_contables
set ebitda = (isnull(ganancia,0) + isnull(amortiza,0) + isnull(res_gasfin,0) - isnull(res_iva,0))
where idifx = @id
update balances_contables
set ind_utilfin = ((isnull(ganancia,0) / isnull(res_vtanet,0)) * 100)
where isnull(res_vtanet,0) != 0
and idifx = @id
update balances_contables
set ind_retpat = (isnull(ganancia,0) / isnull(patrimonio,0))
where isnull(patrimonio,0) != 0
and idifx = @id
update balances_contables
set ind_rentabilidad = ((isnull(ganancia,0) / isnull(act_total,0)) * 100)
where isnull(act_total,0) != 0
and idifx = @id
update BALANCES_COMPLETO_20170831_0 set usuario = 'GASFIN-'+usuario where idifx = @id
Fetch next from bn INTO @fecha, @id, @res_gasfin, @res_resinv, @res_resfin
END
CLOSE bn
DEALLOCATE bn
select @cant as 'CANTIDAD PROCESADA'
END
GO
GO
--exec [balances_res_resinv]
CREATE OR ALTER PROCEDURE dbo.balances_res_resinv
AS
BEGIN
SET NOCOUNT ON;
declare @id int
declare @fecha date
declare @res_gasfin decimal(16,2)
declare @res_resinv decimal(16,2)
declare @res_resfin decimal(16,2)
declare @cant int = 0
drop table tabla_res_gasfin
select distinct fecha_balance, idifx, convert(decimal(16,2),res_gasfin) as res_gasfin,
convert(decimal(16,2),res_resinv) as res_resinv,
convert(decimal(16,2),res_resfin) as res_resfin
into tabla_res_gasfin
from BALANCES_COMPLETO_20170831_0 a
where (convert(decimal(16,2),res_gasfin) != 0.00 or convert(decimal(16,2),res_resinv) != 0.00 or convert(decimal(16,2),res_resfin) != 0.00 )
and usuario not like 'GASFIN-%'
--and fecha_balance >= '1999-01-01'
DECLARE bn CURSOR
FOR
select fecha_balance, convert(int,idifx), res_gasfin, res_resinv, res_resfin
from tabla_res_gasfin
order by fecha_balance desc
OPEN bn
Fetch next from bn INTO @fecha, @id, @res_gasfin, @res_resinv, @res_resfin
WHILE (@@FETCH_STATUS <> -1 )
BEGIN
set @cant = @cant + 1
update balances_contables
set res_gasfin = 0 - @res_gasfin - @res_resfin - @res_resinv,
res_resfin = 0
where idifx = @id
and created_by is null -- para que no toque los que modificaron en el sql a mano
and (modified_by is null or modified_by = 0)
update balances_contables
set ganancia = (isnull(res_vtanet,0)
- isnull(res_cosmer,0)
- isnull(res_gascom,0)
- isnull(res_gasadm,0)
- isnull(res_gasfin,0)
+ isnull(res_otrosing,0)
- isnull(res_otrosegr,0)
+ isnull(res_resfin,0)
- isnull(res_iva,0))
where idifx = @id
update balances_contables
set ebitda = (isnull(ganancia,0) + isnull(amortiza,0) + isnull(res_gasfin,0) - isnull(res_iva,0))
where idifx = @id
update balances_contables
set ind_utilfin = ((isnull(ganancia,0) / isnull(res_vtanet,0)) * 100)
where isnull(res_vtanet,0) != 0
and idifx = @id
update balances_contables
set ind_retpat = (isnull(ganancia,0) / isnull(patrimonio,0))
where isnull(patrimonio,0) != 0
and idifx = @id
update balances_contables
set ind_rentabilidad = ((isnull(ganancia,0) / isnull(act_total,0)) * 100)
where isnull(act_total,0) != 0
and idifx = @id
update BALANCES_COMPLETO_20170831_0 set usuario = 'GASFIN-'+usuario where idifx = @id
Fetch next from bn INTO @fecha, @id, @res_gasfin, @res_resinv, @res_resfin
END
CLOSE bn
DEALLOCATE bn
select @cant as 'CANTIDAD PROCESADA'
END
GO
Depends On
2Used By
No items found