0
我繼承了來自四個表建立庫存查詢與和環比它們輸出的頁面:參考環比CFSpreadsheet
<cfoutput query="getParts">
<cfquery dbtype="query" name="jobdata">
select *
from getJobs
where partnum = '#getparts.partnum#'
</cfquery>
<cfquery dbtype="query" name="orderdata">
select *
from getOrders
where partnum = '#getparts.partnum#'
</cfquery>
<cfquery dbtype="query" name="receiptdata">
select *
from getIncoming
where partnum = '#getparts.partnum#'
</cfquery>
<tr>
<td>#partnum#</td>
<td align="center">#partdescription#</td>
<td align="center">#allocated#</td>
<td align="center">#onhand#</td>
<td align="center">#receiptdata.recqty#</td>
<td align="center">#jobdata.JobCount#</td>
<td align="center">#jobdata.QtyNeeded#</td>
<td align="center">#jobdata.qtySent#</td>
<td align="center">#orderdata.ordercount#</td>
<td align="center">#orderdata.ordered#</td>
<td align="center">#orderdata.shipqty#</td>
</tr>
</cfoutput>
<cfset filenametouse = 'myFile' />
<cfset theDir = GetDirectoryFromPath(GetCurrentTemplatePath()) />
<cfset theFile = theDir & filenametouse & ".xls" />
<cflock name="fileActionSentItems" type="exclusive" timeout="30" throwontimeout="true">
<cfset SpreadsheetObj = spreadsheetNew()>
<cfset fcol = {}>
<cfset fcol.dataformat = "@">
<cfset SpreadsheetAddRow(SpreadsheetObj, "Part Number, Description, Allocated, On Hand, Pending Receipt, Job Count, Qty Needed, Qty Issued, Order Count, Qty Ordered, Qty Shipped")>
<cfset SpreadsheetAddRow(SpreadsheetObj,"NOT SURE HOW TO GET DATA HERE")>
<cfset SpreadsheetFormatColumn(SpreadsheetObj,fcol,11)>
<cfspreadsheet action="write" filename="#theFile#" name="SpreadsheetObj" sheetname="Sheet1" overwrite="true" />
我不能肯定如何引用數據來填充細胞,因爲它來自多個查詢。將查詢重寫爲一個已成爲一項挑戰,我正在嘗試一種不同的方法來查看是否有另一種方法我沒有看到。
回覆:*將查詢重寫爲一個一直是個難題*只是好奇,但多麼複雜的數據庫查詢和多少數據?因爲在循環中查詢通常是最後的手段,即使是QoQ也是如此。 – Leigh 2012-02-08 22:40:29
再次感謝Leigh。 [這些是原始查詢](http://pastebin.com/ZmyPQKTi)。我一直在努力將它們結合在一起,但還沒有走得很遠。 – aparker81 2012-02-09 13:46:50
看起來像前三個都是由相同的partnum和描述聚合。嘗試合併它們,看看總計是否正確。 http://pastebin.com/Fxa0Xkj2 – Leigh 2012-02-09 15:59:38