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
 how to use REAL with comma as "decimal point"?

Author  Topic 

barnabeck
Posting Yak Master

236 Posts

Posted - 2012-01-27 : 04:49:08
We are reading data from an external source that provides ambient temperatures with a comma as the decimal deviding point. Temperatures are in a range from 15,5ºC to 25,6ºC.

This data must be written to a column in SQL and for some reason that should be of real type. Is there a way to accomplish this for just one table or database? Or does a change effects the hole Instance?

Martin

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2012-01-27 : 05:00:32
real is datatype float(24) or what is your question?


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

ditch
Master Smack Fu Yak Hacker

1466 Posts

Posted - 2012-01-27 : 05:04:07
declare @realc varchar(12)
declare @real real

set @realc = '12,5667'
set @real = cast(REPLACE(@realc, ',', '.') as real)

select @realc, @real


Duane.
Go to Top of Page

barnabeck
Posting Yak Master

236 Posts

Posted - 2012-01-27 : 05:25:40
Data is coming in as '25,4' and this value has to be assigned to a column of type real... exactly like that, with the comma. If I remember well there is a way to apply these regional settings for numbers and date to SQL, although I'm afraid that they are apllied to the whole instance rather then just a table or database.
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2012-01-27 : 05:36:58
I think we are talking about
storing a value vs. displaying a value

I don't think there is a need to change how sql server is storing the datatypes.


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

barnabeck
Posting Yak Master

236 Posts

Posted - 2012-01-27 : 05:56:58
yes, you brought it to the point: I was trying to make sql operate using the comma in Real-type; this because of some constraints we are facing and that made me believe that changing the format with the cast wouldn't solve the problem. The command that I remembered vaguely was SET (http://msdn.microsoft.com/us-us/library/ms190356.aspx), but there isn't any argument regarding numbers.

Thank you for your help; I will have to find a workaround with CAST.
Martin
Go to Top of Page
   

- Advertisement -