我在我的数据报告中使用ado shape命令,它工作正常,但当我的聚合函数CALC(agrProfit / agrExtended * 100)为null或0/0 * 100时,它显示一般错误和数据报告未显示。请帮助。
mRS.Open "SHAPE {select products.productid,products.productcode,isnull(products.description,descr) as description,isnull(vendor.description,'*** NOT FOUND ***') as groupdescription, " & _
"isnull(sum(totalcost),0) as mTotalCost,isnull(sum(extended) - (sum(totalcost)),0) as mProfit, " & _
"sum(charges) as mCharges,sum(discount) as mDiscounts, sum(retextended) as mReturns, " & _
"reportuom, sum(totalcost) as mTotalCost, isnull(case when sum(extended) = 0 then 0 else (sum(extended) - (sum(totalcost)))/sum(extended)*100 end,0) as mgpm, sum(totalcost) as mTotalCost, case when sum(extended) = 0 then 0 else (sum(extended) - (sum(totalcost)))/sum(extended)*100 end as mgpm, sum(case when extended < 0 then (0 - (totalqty/products.reportqty)) else (totalqty/products.reportqty) end) as mTotalQty, isnull(sum(extended),0) as mExtended, sum(case when extended < 0 then (0 - (totalqty/products.reportqty)) else (totalqty/products.reportqty) end) / " & mTotalQty & " * 100 as mPercTotalQty, sum(extended) / " & mTotalExtended & " * 100 as mPercExtended " & _
"From " & _
"(select finishedsales.QtyReturned,finishedsales.productid,finishedsales.description as descr, finishedsales.averageunitcost* case when [return]=1 then convert(money,0-totalqty) else totalqty end as TotalCost,(chargeallowance * qty) + (chargeamountdiscounted * qty) as charges,(allowance * qty) + (amountdiscounted * qty)+ (extended-(extended * multiplier)) as discount,0 as rettotalqty, 0 as retextended,totalqty,round(extended * multiplier,4) as extended From finishedsales " & _
" left join products on products.productid = finishedsales.productid " & _
.gReportCriteria & _
"Union All " & _
"select finishedsales.QtyReturned, finishedsales.productid,finishedsales.description as descr,0 as totalcost,0 as charges,0 as discount,totalqty as rettotalqty ,abs(round(extended,4)) as retextended,0 as totalqty, 0 as extended From finishedsales " & _
"left join products on products.productid = finishedsales.productid " & _
Replace(UCase(.gReportCriteria & " and [RETURN] = 1"), "[RETURN] = 0", "[return] = 1") & _
") as finishedsales " & _
"left join products on products.productid=finishedsales.productid " & _
"left join vendor on products.vendorcode=vendor.vendorcode " & _
"group by descr,products.productid,products.productcode,products.description,vendor.description,reportuom " & _
"order by groupdescription, " & IIf(frmReportProducts.chkTop And fVal(frmReportProducts.txtTop) > 0, "finishedsales.mtotalqty desc,", "") & " products.description} AS Command1 COMPUTE Command1, SUM(Command1.mTotalQty) AS agrTotalQty, SUM(Command1.mExtended) AS agrExtended, SUM(Command1.mProfit) AS agrProfit, CALC(agrProfit/agrExtended*100) As agrGPM BY groupdescription", mcn
答案 0 :(得分:2)
所以看起来您在这里使用ADO Data Shaping functions,而import ast
def floyd(graph):
dist = {}
pred = {}
for u in graph:
dist[u] = {}
pred[u] = {}
for v in graph:
dist[u][v] = float('INF')
pred[u][v] = -1
dist[u][u] = 0
for z in graph[u]:
dist[u][z] = graph[u][z]
pred[u][z] = u
for k in graph:
for i in graph:
for j in graph:
if dist[i][k] + dist[k][j] < dist[i][j]:
dist[i][j] = dist[i][k] + dist[k][j]
return dist, pred
graph = {}
graph = ast.literal_eval(open("file2.txt").read())
print graph
dist, pred = floyd(graph)
print " ",
for j in dist: print "__" + str(j),
print "\n"
for i in dist:
print str(i) + "|",
for v in dist: print " %s" % (dist[i][v]),
print "\n"
允许您在表达式中使用列出here的VBA函数。 @ C-Pound Guru的建议导致错误,因为NULLIF()不是VBA函数,但整个表达式可以像这样重写:
CALC(expression)
如果这样可以解决您的问题,请告诉我。
答案 1 :(得分:1)
如果您的SQL Server是2005或更新版本,您可以将NULLIF与ISNULL结合使用:
将<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<stroke
android:width="1dp"
android:color="@color/black" />
</shape>
替换为
agrProfit/agrExtended
当agrExtended = 0时,这将返回零,而不是导致除以零错误。
答案 2 :(得分:0)
您似乎正在使用MS Access或与MS Access接口的东西。如果是这种情况,也许您可以使用Switch
:
替换:
CALC(agrProfit / agrExtended * 100)
使用:
Switch(
ISNULL(SUM(Command1.mExtended)), 0,
ISNULL(SUM(Command1.mProfit)), 0,
IIF(SUM(Command1.mExtended) = 0, 0, SUM(Command1.mProfit) / SUM(Command1.mExtended) * 100)
)
想法是将NULL
替换为0,将0除以0除以0,否则返回实际比率。