¶ÔÓ¦µÄSQLÓï¾äÑùÀý:

	SELECT TA.FNumber FAccountNumber,TA.FName_L1 FAccountName,
	SUM((CASE WHEN TAC.FDC = 1 then TB.FBeginBalanceFor else null end )) FBeginDebitFor, 
	SUM((CASE WHEN TAC.FDC = 1 then null else TB.FBeginBalanceFor end )) FBeginCreditFor, 
	SUM(TB.FDebitFor) FDebitFor,
	SUM(TB.FCreditFor) FCreditFor,
	SUM((CASE WHEN TAC.FDC = 1 then TB.FEndBalanceFor else null end )) FEndDebitFor,
	SUM((CASE WHEN TAC.FDC = 1 then null else TB.FEndBalanceFor end )) FEndCreditFor 
	FROM T_GL_AccountBalance TB
	INNER JOIN T_BD_Period TP
	ON TB.FPeriodID = TP.FID
	INNER JOIN T_BD_Account TA
	ON TB.FAccountID = TA.FID
	INNER JOIN T_BD_Account_Company TAC
	ON TA.FID = TAC.FAccountID
	INNER JOIN T_ORG_Company TCP
	ON TAC.FCompanyID = TCP.FID
	WHERE
	TCP.FAccountPeriodID = TP.FTypeID AND 
	TB.FBalType = 1	AND
	TB.FCurrencyID = '' AND
	TP.FTypeID = '' AND
	(TP.FPeriodYear*100 + TP.FPeriodNumber) >= (2003*100+12) AND
	(TP.FPeriodYear*100 + TP.FPeriodNumber) <= (2004*100+3) AND 
	TAC.FCompanyID = '' AND
	TA.FAccountTableID = '' AND
	TA.FAccountTypeID = '' AND
	TA.FLevel <= 1 AND
	(
		TB.FBeginBalanceFor <> 0 OR
		TB.FDebitFor <> 0 OR
		TB.FCreditFor <> 0 OR
		TB.FEndBalanceFor <> 0 )
		group by TA.FNumber,TA.FName_L1,TB.FCurrencyID
	ORDER BY TA.FNumber

