Wednesday, March 28, 2012

How to force SQL Server to handle all numeric types as doubles?

Hi, is it possible to force SQL Server to handle all numeric data types as
doubles? Eg. I have an very simple query:
SELECT 1+1 AS Result
I need SQL Server to work with number 1 as with double and also to return a
result as a double (however it doesn't make any sence in this situation).
Thanks.Hi
I don't think there is an automatic way, but you can use the CAST/CONVERT
functions. Also check out the topic "Data Type Precedence" in Books Online.
John
"Tomas Machala" <t.machala@.tiscali.cz> wrote in message
news:%23X$A60tDGHA.3988@.TK2MSFTNGP12.phx.gbl...
> Hi, is it possible to force SQL Server to handle all numeric data types as
> doubles? Eg. I have an very simple query:
> SELECT 1+1 AS Result
> I need SQL Server to work with number 1 as with double and also to return
> a result as a double (however it doesn't make any sence in this
> situation).
> Thanks.
>|||Tomas Machala (t.machala@.tiscali.cz) writes:
> Hi, is it possible to force SQL Server to handle all numeric data types as
> doubles? Eg. I have an very simple query:
> SELECT 1+1 AS Result
> I need SQL Server to work with number 1 as with double and also to
> return a result as a double (however it doesn't make any sence in this
> situation).
The one way, is to express the numbers as floats. So in your example:
SELECT 1E0+1E0 AS Result
Note that in an expression like:
SELECT 1E0 + 1 Result
The integer one will be automatically converted to float.
Erland Sommarskog, SQL Server MVP, esquel@.sommarskog.se
Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pr...oads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodin...ions/books.mspx

No comments:

Post a Comment