dbo.balances_res_otros

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


BEGIN
    SET NOCOUNT ON;
 declare @id int 
 declare @res_otros decimal(16,2)
 declare @cant int = 0

-- drop table tabla_res_otros 

select distinct idifx, convert(decimal(16,2),res_otros) as res_otros
into tabla_res_otros 
from BALANCES_COMPLETO_20170831_0 a 
where convert(decimal(16,2),res_otros) != 0.00

DECLARE bn CURSOR
FOR
 select convert(int,idifx), res_otros
   from tabla_res_otros 
  order by convert(int,idifx )
  
 OPEN bn 
 Fetch next from bn INTO @id, @res_otros 
 
 WHILE (@@FETCH_STATUS <> -1 )
 BEGIN
     set @cant = @cant + 1
  if (@res_otros > 0) 
  begin
   update balances_contables set res_otrosing = res_otrosing + @res_otros
    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
  end 
  else
  begin
            
   update balances_contables  set res_otrosegr = res_otrosegr * (-1)
    where idifx = @id
      and res_otrosegr < 0 

   update balances_contables  set res_otrosegr = res_otrosegr + (@res_otros * (-1))
    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
  end 
  update BALANCES_COMPLETO_20170831_0 set usuario = 'RES_OTROS'+usuario where idifx = @id 
  
    Fetch next from bn INTO @id, @res_otros 
 END

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

GO

Used By

No items found