SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO
IF EXISTS (SELECT name FROM sysobjects 
         WHERE name = 'CIZACLBA' AND type = 'P')
   DROP PROCEDURE RPTUSER.CIZACLBA
GO


CREATE PROCEDURE RPTUSER.CIZACLBA
@P_ACCT_ID CHAR(10)

AS

/******************************************************************************
   NAME:       CIZACLBA
   PURPOSE:    

******************************************************************************/
BEGIN

    SELECT A.BILL_DT,
        SUM( B.CUR_AMT) CUR_AMT,
        B.CURRENCY_CD,
        C.CUR_SYMBOL,
        C.DECIMAL_POSITIONS,
        C.SCALE_POSITIONS,
        C.CUR_POS_FLG
    FROM   
        CI_BILL A, 
        CI_BILL_SA B, 
        CI_CURRENCY_CD C
    WHERE  
        A.ACCT_ID = @P_ACCT_ID
        AND A.BILL_ID = B.BILL_ID
        AND A.BILL_STAT_FLG = 'C'
        AND A.BILL_DT = (
            SELECT MAX (D.BILL_DT)
            FROM CI_BILL D
            WHERE  
                D.ACCT_ID = A.ACCT_ID
                AND D.BILL_STAT_FLG = 'C')
        AND B.CURRENCY_CD = C.CURRENCY_CD
    GROUP BY  
        A.BILL_DT,
        B.CURRENCY_CD,
        C.CUR_SYMBOL,
        C.DECIMAL_POSITIONS,
        C.SCALE_POSITIONS,
        C.CUR_POS_FLG
			 
RETURN

END



GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

