Quantcast
Channel: Teradata Forums - All forums
Viewing all articles
Browse latest Browse all 27759

Division by zero Error - forum topic by SANJI

$
0
0

I'm trying to execute a query which fails on divide by zero error.
Can't use a NULLIFZERO because the AJI would be ignored.
Following is the query which fails on "SELECT Failed. 2618: Invalid Calculation: Division by zero"

SELECT DISTINCT C0, C1, AVG(C2) OVER (PARTITION BY C0,C1) AS C5
FROM
(SELECT Equipment_Category.Category_Code    C0 ,
    Equipment_Class.Cat_Class_Description     C1 ,
    SUM(Equipment_Daily_Metrics.c10)     C2  
 FROM
 (
  (CG_EQPT_CATEGORY Equipment_Category
  INNER JOIN
  (SELECT SUBSTRING ('000' || TRIM(BOTH FROM Category_Code) FROM 1 + CHAR_LENGTH (TRIM(BOTH FROM Category_Code))) || '-' ||
      SUBSTRING ('0000' || TRIM(BOTH FROM Class_Code) FROM 1 + CHAR_LENGTH (TRIM(BOTH FROM Class_Code))) || '' ||
      CG.Class_Name AS Cat_Class_Description,
      CG.Category_Code Category_Code,
      CG.Class_Code Class_Code
   FROM CG_ITEM_EQPT_CLASS CG
  ) Equipment_Class
  ON Equipment_Category.Category_Code = Equipment_Class.Category_Code
  )
  INNER JOIN
  (SELECT Equipment_Cost_Amt C10 ,Category_Code, Class_Code
   FROM CG_EQUIPMENT_DAILY_FACT) Equipment_Daily_Metrics
  ON Equipment_Class.Category_Code = Equipment_Daily_Metrics.Category_Code
  AND Equipment_Class.Class_Code = Equipment_Daily_Metrics.Class_Code
  )
 GROUP BY C0, C1
) T0
WHERE T0.C0 BETWEEN 100 AND 200

Couple of other scenarios...
I included the following clause in the query and it didn't error out.

WHERE T0.C2 <> 0
AND   T0.C0 BETWEEN 100 AND 200

However when i attempt to see which are offending recods by querying the following, there are none.
WHERE T0.C2 = 0
AND   T0.C0 BETWEEN 100 AND 200

Also, I can create a table over this query and can successfully query from it
SELECT DISTINCT C0,C1, AVG(C2) OVER (PARTITION BY C0,C1) C5 FROM SSURI.TEST1;

Why would the query fail on division by zero error if there aren't any T2.C2 = 0 records.

Forums: 

Viewing all articles
Browse latest Browse all 27759

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>