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 2000 Forums
 Transact-SQL (2000)
 Convert text string with exponent to numeric value

Author  Topic 

hvdtol
Yak Posting Veteran

50 Posts

Posted - 2003-01-03 : 09:25:40
I am facing a strange problem.
I want to convert a text value to a numeric value.
One of the values has an exponent.
When i run underneath script in an development machine, it works fine.
----
declare @value_num decimal (18,6)
declare @value_str varchar(21)

set @value_str = '2.275927000000e+006'

SELECT @value_num = convert(decimal(18,6),(CONVERT(float, CONVERT(varchar(25), @value_str ) ) ) )

print @value_num

Result: 2275927.000000
-----
But when i run it in the production machine i receive a error.

Server: Msg 8114, Level 16, State 5, Line 4
Error converting data type varchar to float.

-----------

Both machines are Win2000, with the exact same Mssql7.0 version and patch level, same code page.

I can solve it, when i change the dot into a comma, then it runs fine. Like this

set @value_str = '2,275927000000e+006'

Does anyone knows what the differnce between the to machines can be?

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2003-01-03 : 16:02:17
Compare the results of this query on both systems:
SELECT SERVERPROPERTY(N'Collation')


Go to Top of Page

hvdtol
Yak Posting Veteran

50 Posts

Posted - 2003-01-04 : 12:06:56
Is this perhaps a Sql2000 function?, because i receive message ' function not recognized'
I use Sql 7.0

Go to Top of Page

harshal_in
Aged Yak Warrior

633 Posts

Posted - 2003-01-06 : 01:13:28
quote:

Is this perhaps a Sql2000 function?, because i receive message ' function not recognized'
I use Sql 7.0





Yes,SERVERPROPERTY IS SQL2000 function.

Expect the UnExpected
Go to Top of Page

AndrewMurphy
Master Smack Fu Yak Hacker

2916 Posts

Posted - 2003-01-06 : 09:09:16
sounds like you have different REGIONAL settings.....on the 2 machines....not at client-PC level....but on the server itself.


check the control-panel, regional settings, "number" tab....and see if there are any differences....(a change may require a reboot to become active)

there are several conventions for displaying numbers...depending on which country you are in.....(it's mainly a northern European problem)

Go to Top of Page

hvdtol
Yak Posting Veteran

50 Posts

Posted - 2003-01-07 : 06:12:17
I checked all the tab-sheets regional settings, but they are all the same.
I've decided to add the REPLACE instruction to my sql.
Anyway thanks for you help.

Go to Top of Page
   

- Advertisement -