Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove decimal values using SQL query

Tags:

sql

sql-server

I am having following values in database table :

12.00
15.00
18.00
20.00

I want to remove all decimal ZEROS from all values , So how can I do this using SQL query. I tried replace query but that is not working.

I want values like :

12
15
18
20

My replace query :

       select height(replace (12.00, '')) from table;

Please help.

like image 575
rahul bhatt Avatar asked Jan 07 '15 15:01

rahul bhatt


People also ask

How do you remove a decimal value?

Step 1: Write down the decimal divided by 1. Step 2: Multiply both top and bottom by 10 for every number after the decimal point. (For example, if there are two numbers after the decimal point, then use 100, if there are three then use 1000, etc.) Step 3: Simplify (or reduce) the Rational number.

How do you remove numbers after 2 decimal places in SQL?

The TRUNCATE() function truncates a number to the specified number of decimal places.

How do you remove decimals without rounding in SQL?

To get rid of all decimal places without regard to their value, use the INT() function (short for integer). This function takes one argument, the value, and returns whatever is to the left of the decimal point. To get rid of some decimal places without and rounding, use TRUNC(), which is short of truncate.


1 Answers

Since all your values end with ".00", there will be no rounding issues, this will work

SELECT CAST(columnname AS INT) AS columnname from tablename

to update

UPDATE tablename
SET columnname = CAST(columnname AS INT)
WHERE .....
like image 168
Dbloch Avatar answered Sep 26 '22 12:09

Dbloch