dbo.balances_res_otros_2

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_otros_2]
CREATE OR ALTER PROCEDURE dbo.balances_res_otros_2
AS


BEGIN
    SET NOCOUNT ON;
 declare @id int 
 declare @cant int = 0

DECLARE bn CURSOR
FOR
 select convert(int,idifx)
   from tabla_res_otros 
  order by convert(int,idifx)
  
 OPEN bn 
 Fetch next from bn INTO @id
 
 WHILE (@@FETCH_STATUS <> -1 )
 BEGIN
     set @cant = @cant + 1
  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 = 'TOTALES-'+usuario where idifx = @id 
    
  Fetch next from bn INTO @id
 END

 CLOSE bn
 DEALLOCATE bn 
 select @cant as 'CANTIDAD PROCESADA' 
END 

GO

Depends On

1

Used By

No items found