WeeklyDad
WeeklyDad

Reputation: 317

Removing decimals in SQL Query

My question is rather short but I have a issue finding a answer. But I have a select in SQL that has the following search:

Max(CashTrans.Costprice)

In my result in SQL I get the following

-1180,00
-1377,502
-0,40
-460,00
-100,00
-100,00
-100,00
-100,00
-100,00

What is the most effective and easiest way removing "," and all decimals after so the result would end up with

-1180
-1377
-0
-460
-100
-100
-100
-100
-100

Thanks and have a good day!

Upvotes: 2

Views: 12703

Answers (4)

Chanukya
Chanukya

Reputation: 5873

SELECT CAST(columnname AS INT) AS columnname from tablename

or

Select 
SUBSTRING(a,0,CHARINDEX(',',a)) from #Table2

Upvotes: 1

mohan111
mohan111

Reputation: 8865

IF we are not sure of data types and instead of dealing with conversion errors

Select 
SUBSTRING(ID,0,CHARINDEX(',',ID)) from Table

Upvotes: 0

HoneyBadger
HoneyBadger

Reputation: 15130

You can try:

CONVERT(INT, Max(CashTrans.Costprice))

Upvotes: 4

juergen d
juergen d

Reputation: 204746

select Max(cast(CashTrans.Costprice as int))
from your_table
...

Upvotes: 0

Related Questions