CF Not Returning Correct Results
I have a column that has both positive and negative numbers and I am trying to seperate those numbers into a seperate column each. My code below is working if each barcode has both a positive and negative number to compare, but errors are thrown such as "can't convert " to a numeric value" if I just have all positive numbers in the colum. Which, in some casees, I will have because I am importing a CSV file. Can anyone help with the code? - Thanks.
<!--- SUM POSITVE QUANTITY --->
<cfquery name="SumPositiveTemp" datasource='inventory'>
SELECT barcode, sum(quantity) as quantitysumPositive
FROM temp
WHERE Quantity > 0
GROUP BY barcode
</cfquery>
<!--- SUM NEGATIVE QUANTITY --->
<cfquery name="SumNegativeTemp" datasource='inventory'>
SELECT barcode, sum(quantity) as quantitysumNegative
FROM temp
WHERE Quantity < 0
GROUP BY barcode
</cfquery>
<!--- SUBTRACT QUANTITY ISSUED MINUS QUANTITY RECEIVED TO GET QUANTITY SOLD --->
<cfset QuanitySold = '#SumPositiveTemp.quantitysumPositve-SumNegativeTempquantitysumNegative#'>
<!--- INSERT POSITVIE/NEGATIVE NUMBERS INTO TABLE--->
<cfoutput query="SumPositiveTemp">
<cfquery name="InsertPositiveIntoCart" datasource="inventory">
INSERT INTO Cart1 (barcode, QuantityOut, QuantityIn, QuantitySold)
VALUES (#SumPositiveTemp.barcode#, #SumPositiveTemp.quantitysumPositive#, #SumNegativeTemp.quantitysumNegative#, #QuantitySold#)
</cfquery>
</cfoutput>
