dbo.sp_balances_2007_grupos

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

--select * from balances_contables where cuit = '20005717915'
--select * from balances_por_grupo
CREATE OR ALTER PROCEDURE dbo.sp_balances_2007_grupos

AS
BEGIN
SET NOCOUNT ON;
delete from balances_por_grupo
insert into balances_por_grupo (cuit, cod_clae, grupo, fecha_balance, ventas_netas)
select  balances_contables.cuit, 
        --padrones.nombre_persona, 
  clae.cod_clae, 
  --clae.descripcion, 
  ramos.cod_ramo as grupo, 
  --ramos.descripcion as nom_grupo,
  fecha_balance as fecha_balance, 
  res_vtanet 
from balances_contables 
--inner join padrones on identificacion = cuit and habilitado = 1 and identificador in ('CUIT','CUIL')
left join clae on clae.cuit = balances_contables.cuit and clae.formulario = 883 and principal = 1 
left join ramos r on r.formulario = '883' and cod_subramo = clae.cod_clae
left join ramos on ramos.cod_ramo = r.cod_ramo and ramos.tipo_ramo = 'R'
where balances_contables.bal_manifestacion = 'B'
  and balances_contables.fecha_balance >= '2007-01-01' 
  and balances_contables.estado = 'PUBLICADO' 
  and balances_contables.visible = 1  
  and isnull(balances_contables.res_vtanet,0) > 0
  and balances_contables.fecha_balance = 
      (select max(b.fecha_balance) from balances_contables b 
                    where b.cuit = balances_contables.cuit  
       and b.estado = 'PUBLICADO'
       and b.visible = 1 
       and isnull(b.res_vtanet,0) > 0
       )
  and ramos.cod_ramo is not null

END 

GO

Used By

No items found