SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 error converting nvarchar to float
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

nietzky
Yak Posting Veteran

72 Posts

Posted - 05/20/2013 :  11:38:07  Show Profile  Reply with Quote
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

Edited by - nietzky on 05/20/2013 11:42:10

MuMu88
Aged Yak Warrior

547 Posts

Posted - 05/20/2013 :  12:19:47  Show Profile  Reply with Quote
What is the error?
Can you try the following:

DECLARE @val1 nvarchar(384);
SET @val1 = '55.393';
SELECT CAST(LTRIM(RTRIM(@val1)) as NUMERIC(12,3));

Edited by - MuMu88 on 05/20/2013 12:20:29
Go to Top of Page

nietzky
Yak Posting Veteran

72 Posts

Posted - 05/20/2013 :  12:33:49  Show Profile  Reply with Quote
Thank you. It works now.
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.03 seconds. Powered By: Snitz Forums 2000