on 03-09-2018 1:24 PM
Hi,
I sort of understand why I get an error message, but I am unable to solve it.
Here's what I have done. And I'd like to see resuts even if they are negative. We also have quantity on invoices which are negative.
Any takers on heping me?
SAP B1 HANA
*Edit: full error message:
1). [SAP AG][LIBODBCHDB32 DLL][HDBODBC32] General error;304 division by zero undefined: search table error: [6859] AttributeEngine: divide by zero;decfloat comma '' (SWEI) (fixed12_16.6 sqlsub(fixed12_16.6 "SEPTON.INV1.Price", fixed12_16.6 "SEPTON.INV1
SELECT T0."CardCode", T0."CardName", T0."DocNum", T1."ItemCode", T1."Dscription", T1."Quantity", T1."LineTotal", T1."StockPrice", SUM(T1."Price"-T1."StockPrice")*T1."Quantity" AS "Bruttovinst", SUM((T1."Price"-T1."StockPrice")*T1."Quantity"/T1."LineTotal")*100 AS "Bruttovinst", T3."Price", T3."Currency"
FROM OINV T0
INNER JOIN INV1 T1 ON T0."DocEntry" = T1."DocEntry"
INNER JOIN OITM T2 ON T1."ItemCode" = T2."ItemCode"
INNER JOIN ITM1 T3 ON T2."ItemCode" = T3."ItemCode"
INNER JOIN OPLN T4 ON T3."PriceList" = T4."ListNum"
WHERE T0."DocDate" >=[%0] AND T0."DocDate" <=[%1] AND T3."PriceList" ='1' AND T1."LineStatus" = 'O'
GROUP BY T0."CardCode", T0."CardName", T0."DocNum", T1."ItemCode", T1."Dscription", T1."Quantity", T1."LineTotal", T1."StockPrice", T3."Price", T3."Currency"
I SUSPECT THIS CODE GIVING YOU ERROR SUM((T1."Price"-T1."StockPrice")*T1."Quantity"/T1."LineTotal")*100 AS "Bruttovinst"
TAKE ANOTHER APPROACH USING CASE WHEN
CASE WHEN T1."LineTotal" =0 THEN 0
ELSE SUM((T1."Price"-T1."StockPrice")*T1."Quantity"/T1."LineTotal")*100
END AS "Bruttovinst"
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You probably have some T1."LineTotal" = ZERO
Maybe you can run your query to find out where this is happening
SELECT T0."DocEntry" FROM OINV T0
INNER JOIN INV1 T1 ON T0."DocEntry" = T1."DocEntry"
INNER JOIN OITM T2 ON T1."ItemCode" = T2."ItemCode" INNERJOIN ITM1 T3 ON T2."ItemCode" = T3."ItemCode"
INNER JOIN OPLN T4 ON T3."PriceList" = T4."ListNum" WHERE T0."DocDate" >=[%0] AND T0."DocDate" <=[%1] AND T3."PriceList" ='1' AND T1."LineStatus" = 'O' AND T1."LineTotal" = 0
Or change to 1 whenever LineTotal = 0 or Quantity = 0
SELECT T0."CardCode", T0."CardName", T0."DocNum", T1."ItemCode", T1."Dscription", T1."Quantity", T1."LineTotal", T1."StockPrice", SUM(T1."Price"-T1."StockPrice")*CASE WHEN T1."Quantity" = 0 THEN 1 else T1."Quantity" END AS "Bruttovinst", SUM((T1."Price"-T1."StockPrice")*CASE WHEN T1."Quantity" = 0 THEN 1 else T1."Quantity" END/CASE WHEN T1."LineTotal" = 0 THEN 1 else T1."LineTotal" end)*100.00 AS "Bruttovinst", T3."Price", T3."Currency" FROM OINV T0 INNER JOIN INV1 T1 ON T0."DocEntry" = T1."DocEntry" INNER JOIN OITM T2 ON T1."ItemCode" = T2."ItemCode" INNER JOIN ITM1 T3 ON T2."ItemCode" = T3."ItemCode" INNER JOIN OPLN T4 ON T3."PriceList" = T4."ListNum" WHERE T3."PriceList" ='1' AND T1."LineStatus" = 'O' GROUP BY T0."CardCode", T0."CardName", T0."DocNum", T1."ItemCode", T1."Dscription", T1."Quantity", T1."LineTotal", T1."StockPrice", T3."Price", T3."Currency"
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
82 | |
11 | |
10 | |
8 | |
6 | |
6 | |
6 | |
6 | |
5 | |
5 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.