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
 Convert from one type to an other?

Author  Topic 

landau66
Yak Posting Veteran

61 Posts

Posted - 2009-02-12 : 08:37:29
Hello!

I have a table in which every column has the type nvarchar. In 4 of this columns i have values like 1,45682(=1.45682). I want to convert this to a double value. How can i achieve that?

Many thanks and greetings

Landau

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2009-02-12 : 08:39:30
SELECT Col1, CASE ISNUMERIC(Col1) WHEN 0 THEN NULL ELSE CONVERT(FLOAT, Col1) END
FROM Table1



E 12°55'05.63"
N 56°04'39.26"
Go to Top of Page

sakets_2000
Master Smack Fu Yak Hacker

1472 Posts

Posted - 2009-02-12 : 08:42:09

SELECT Col1, CASE ISNUMERIC(replace(Col1,',','.')) WHEN 0 THEN NULL ELSE CONVERT(FLOAT, replace(Col1,',','.')) END
FROM Table1
Go to Top of Page

landau66
Yak Posting Veteran

61 Posts

Posted - 2009-02-12 : 08:51:54
well, that is not working. I get an error messages:
Message 8114, Level 16, Status 5, Row 1

I tried it also via the sqlserver management studio. I converted it and the result was that a 1,33055 became 133055,0000.

Any ideas?

Thanks, Landau

Go to Top of Page

sakets_2000
Master Smack Fu Yak Hacker

1472 Posts

Posted - 2009-02-12 : 09:03:35
show us the query that you ran.
Go to Top of Page

landau66
Yak Posting Veteran

61 Posts

Posted - 2009-02-12 : 09:09:51
SELECT [Spalte 1], CASE ISNUMERIC([Spalte 1]) WHEN 0 THEN NULL ELSE CONVERT(FLOAT, [Spalte 1]) END
FROM Test
Go to Top of Page

sakets_2000
Master Smack Fu Yak Hacker

1472 Posts

Posted - 2009-02-12 : 09:23:51
Try the query that I gave you.
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2009-02-12 : 09:24:42
Try sakets suggestion with the REPLACE thingy...


E 12°55'05.63"
N 56°04'39.26"
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2009-02-12 : 09:24:54



E 12°55'05.63"
N 56°04'39.26"
Go to Top of Page

landau66
Yak Posting Veteran

61 Posts

Posted - 2009-02-13 : 02:50:46
Hi!

Thanks a lot - it is working perfectly.

Greetings, Landau
Go to Top of Page
   

- Advertisement -