0

I try to divide to decimal columns But keeps returns zeros if after casting to decimal

For example

A B 677.00 900.00

A/B

Returns 0.000

I try to divide to decimal columns But keeps returns zeros if after casting to decimal

For example

A B 677.00 900.00

A/B

Returns 0.000

expecting 0.67

Ghaida
  • 19
  • 1
  • Well for me it return .75, not .67. But funny math aside, how are your columns defined? – Andrew Jun 20 '23 at 20:59
  • What client / which driver are you using to connect? This could possibly be a client issue if none of the suggestions here help you. – Fred Jun 21 '23 at 18:31

1 Answers1

0

To get the value after the decimal then try the following query. Where 2 represents the decimal values you would like to return: -

SELECT CAST(A AS DECIMAL(10, 2)) / CAST(B AS DECIMAL(10, 2)) (DECIMAL(10, 2)) AS Result
FROM Table_Name;
Venkat
  • 549
  • 6
  • Tried it but still returns 0.00 – Ghaida Jun 21 '23 at 06:43
  • @Ghaida - You don't even need all of those casts - `select cast(600 as decimal(10,2)) / 900` returns `0.67`. Please update your post with sample data (in a volatile table would be best) and your query. – Andrew Jun 21 '23 at 14:34