2012-11-29 37 views
0

我想選擇上個月的期末餘額並將其用作下月的期初餘額,但我似乎沒有得到正確的結果。select語句將期末餘額結轉到以下

我已經使用這個代碼來選擇其它列,取得平衡:

SELECT Year1,StockNumber,InventoryName,Month1, 
     SUM(ABS(RECEIVE_FROM_PO)) AS RPO,SUM(ABS(RECEIVE_XFER))AS XEFR, 
     SUM(ABS(RECEIVE_ADJ)) as RDJ,SUM(ABS(RETURN1)) AS RET, 
     SUM(ABS(TRANSFER)) as TSFR,SUM(ABS(ISSUE)) as ISS, SUM(ABS(PT_ISSUE))as PISS, 
     SUM(ABS(ADJUSTMENT)) as ADJ, 
     (Sum(ABS(RECEIVE_FROM_PO + RECEIVE_XFER + RECEIVE_ADJ + RETURN1)) - Sum(ABS(TRANSFER+ISSUE+PT_ISSUE+ADJUSTMENT))) as Balance 
FROM dbo.Sheet2$ 
where Year1 ='' and InventoryName ='' and StockNumber ='' 
GROUP BY Year1,InventoryName,StockNumber,Month1,balance 

有了這個代碼,我能夠取得平衡,現在我想用這種平衡作爲下一個月期初餘額。 SQL腳本如何使用Crystal Reports完成?

回答

0

Crystal報表具有完成羣組功能的能力,如sum,min,max等。它具有所有豐富的功能。如果創建查詢失敗,請在Crystal報表中獲取表Sheet2 $,然後爲查詢中的每個總和創建彙總字段。

相關問題