IF EXISTS ( SELECT * 
            FROM   sysobjects 
            WHERE  id = object_id(N'CPJ_Asiento_Agregar') 
                   and OBJECTPROPERTY(id, N'IsProcedure') = 1 )
BEGIN
    DROP PROCEDURE CPJ_Asiento_Agregar
END
GO

CREATE PROCEDURE [dbo].[CPJ_Asiento_Agregar] 

AS
 
DECLARE @ID_ASIENTO INT
 
SET @ID_ASIENTO = ISNULL((SELECT MAX(ID_ASIENTO) FROM ASIENTOS),0)+1
 
INSERT INTO ASIENTOS (ID_ASIENTO,DESCRIPCION,Id_Unid_Negocio,Id_Plan_Cta,Fecha) VALUES (@ID_ASIENTO,'','',0,Getdate())
 
SELECT @ID_ASIENTO AS Id_Asiento
