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
 SQL Server 2008 Forums
 Transact-SQL (2008)
 error converting nvarchar to float

Author  Topic 

nietzky
Yak Posting Veteran

75 Posts

Posted - 2013-05-20 : 11:38:07
Can someone tell me how to convert nvarchar to float or numeric when data to be converted may have .961 string, sometimes starts with "."? I am getting error when I try to convert data that comes from OPENQUERY (from Oracle box). Thank you


select CAST(AvgCPU as numeric(12,3)) - fails

AvgCPU is currently stored as nvarchar(384)

49
1.553
1.911
48.485
35.774
43
.961
.554
43
41.7
42.837
41.778
.848
1.15
37
37
45.765
.52
46.182
37.167
.512
5.613
49.2
6.312
45.803
21.941
46.53
21.909
6.092
.635
55.393
47.993
33.006
.435
33.04

MuMu88
Aged Yak Warrior

549 Posts

Posted - 2013-05-20 : 12:19:47
What is the error?
Can you try the following:
[CODE]
DECLARE @val1 nvarchar(384);
SET @val1 = '55.393';
SELECT CAST(LTRIM(RTRIM(@val1)) as NUMERIC(12,3));
[/CODE]
Go to Top of Page

nietzky
Yak Posting Veteran

75 Posts

Posted - 2013-05-20 : 12:33:49
Thank you. It works now.
Go to Top of Page
   

- Advertisement -