1
私のクエリでは、平均を計算するときに、ゼロによる除算が発生します。私はNullifを使用してこれを解決しようとしていますが、Coldfusionが ')'の近くに不正な構文を示すエラーをスローするため、構文が正しいとは思われません。ゼロで除算を防止するNullIf()
私のクエリは次のとおりです。
<cfquery name="getValueAdd" datasource="#myDSN#">
select d.partnum, sum(docunitprice * orderqty) as total_sales,
sum((c.avglaborcost + c.avgburdencost + c.avgmaterialcost + c.avgsubcontcost + c.avgmtlburcost)*d.orderqty) as total_cost,
sum((docunitprice * orderqty)-((c.avglaborcost + c.avgburdencost + c.avgmaterialcost + c.avgsubcontcost + c.avgmtlburcost)*d.orderqty)) as Value_add,
avg (isNull(
((((docunitprice * orderqty)-((c.avglaborcost + c.avgburdencost + c.avgmaterialcost + c.avgsubcontcost + c.avgmtlburcost)*d.orderqty))/ (nullIf(docunitprice * orderqty), 0),0)
))) as PercValueAdd
from orderhed h with(nolock), orderdtl d with(nolock), partcost c with(nolock)
where h.company = 'PC68300'
and d.company = h.company
and c.company = h.company
and d.ordernum = h.ordernum
and c.partnum = d.partnum
and hdcasenum = <cfqueryparam cfsqltype="cf_sql_integer" value="#rc.hdcasenum#" />
group by d.partnum
</cfquery>
誰も私の構文を明確にすることができますしてください?
+1彼らは 'NULLIF(expression_that_might_be_zero、0)'ゼロはNULL' 'に変換取得し、それがエラーを起こさないようにする必要があります。 –
私はこれがここにあると信じています:(nullIf(docunitprice * orderqty)、0)。これは間違っていますか? – aparker81
@ aparker81の場合、あなたはあなたの 'nullif'ステートメントの一つにその構文しかありません。 – Ben