
/****** Object:  StoredProcedure [dbo].[PCONTSALD]    Script Date: 02/08/2017 13:08:51 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO



ALTER   procedure [dbo].[PCONTSALD] (@ejer smallint = null)
AS  

declare @idejer int

if(@ejer is null)
	select @idejer=id_ejer from CONTTABL
else 
	select @idejer=id_ejer from contejer where ejercicio=@ejer

DELETE CONTSALD where id_ejer=@idejer
INSERT CONTSALD SELECT id_cuenta, id_peri, id_ejer, id_empr,
                       sum(importe*tasa*debito) as debe,
                       sum((importe-importe*debito)*tasa) as haber
                 FROM CONTDIAR d INNER JOIN CONTDIAM m ON d.id_diam=m.id_diam
                 WHERE id_ejer=@idejer
                 GROUP BY id_cuenta,id_peri,id_ejer,id_empr


Return 






















