Tuesday, March 27, 2012

convert

why do the results of the following sql are 0
select convert(int, 0.9)
select cast(0.9 as int)Win you are using int which is not supported with decimal try to use float
and you will have the right results..
Best regards
Shailesh Gothal
"Win" wrote:

> why do the results of the following sql are 0
> select convert(int, 0.9)
> select cast(0.9 as int)
>
>|||If you are expecting this to round up, it won't. You'll
find this mentioned in BOL in "CAST and CONVERT"
Note that using decimal(10,0) instead of int will round
select convert(decimal(10,0), 0.9)
select cast(0.9 as decimal(10,0))|||Win
So what do you suppose to get?
You convert to INTEGER not DECIMAL or something else
select cast(0.9 as decimal(5,2))
"Win" <aaa@.aaa.com> wrote in message
news:OOHe11tMGHA.2668@.tk2msftngp13.phx.gbl...
> why do the results of the following sql are 0
> select convert(int, 0.9)
> select cast(0.9 as int)
>|||Thats quite normal, the int representation of 0.9 is 0.
What did you expect ?
HTH, Jens Suessmeyer.sqlsql

No comments:

Post a Comment