cancel
Showing results for 
Search instead for 
Did you mean: 

Usage of TO_DECIMAL and SUM together

lee_haire3
Discoverer
0 Kudos
184
  • SAP Managed Tags:

I came across some SQL code that uses the 2 expressions TO_DECIMAL and SUM together. In some cases, the TO_DECIMAL is used first (followed by SUM) and other cases it's the other way around. 

Case A: TO_DECIMAL (SUM (xyz), 25, 10)

Case B: SUM( TO_DECIMAL(xyz, 25, 10) )

I'm uncertain if there is any difference in the result depending on which way you sequence them? Which sequence is recommended?

View Entire Topic
MD1
Active Contributor
0 Kudos

Hi,

Using these examples in your database will help you

--Case A: Using TO_DECIMAL After SUM

SELECT
TO_DECIMAL(SUM(sales_amount), 25, 10) AS total_sales
FROM
sales_data;

--Case B: Using SUM After TO_DECIMAL

SELECT
SUM(TO_DECIMAL(sales_amount, 25, 10)) AS total_sales
FROM
sales_data;