Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 select statement - converting text into decimal

Author  Topic 

jcarrallo
Starting Member

35 Posts

Posted - 2014-07-05 : 09:39:30
Hi,
I have trouble converting a text field into decimals in a select statement.

The select statement is as follows:

select cast(ltrim(rtrim(units)) as decimal) as units

and I get an error message:

Msg 8114, Level 16, State 5, Line 23
Error converting data type nvarchar to numeric.


and the 'units' column contains ' 324,32 '

Can anyone help?
many thanks,
jay

bitsmed
Aged Yak Warrior

545 Posts

Posted - 2014-07-05 : 12:56:56
You probably need to replace the comma to period:
select cast(ltrim(rtrim(replace(units,',','.'))) as decimal) as units

Go to Top of Page

jcarrallo
Starting Member

35 Posts

Posted - 2014-07-05 : 22:21:46
great!
many thanks
jay
Go to Top of Page
   

- Advertisement -