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 2005 Forums
 Transact-SQL (2005)
 float number

Author  Topic 

agniwoni
Starting Member

28 Posts

Posted - 2008-01-25 : 04:35:42
If i give SQLSrv following command:
SELECT 1/2

it will give me:
0

it is a result in intiger format...
What to do to receive:
0.5?

regards
Agni

ayamas
Aged Yak Warrior

552 Posts

Posted - 2008-01-25 : 04:55:34

declare @num real
declare @num1 real
set @num=1
set @num1=2

select @num/@num1
Go to Top of Page

agniwoni
Starting Member

28 Posts

Posted - 2008-01-25 : 04:56:47
select 1.0 / 2.0
also works!

thanks!
Go to Top of Page

agniwoni
Starting Member

28 Posts

Posted - 2008-01-25 : 05:01:12
more!
select 1.0/2
works!!!!

God exists!
Go to Top of Page

ayamas
Aged Yak Warrior

552 Posts

Posted - 2008-01-25 : 05:27:05
quote:
Originally posted by agniwoni

If i give SQLSrv following command:
SELECT 1/2

it will give me:
0

it is a result in intiger format...
What to do to receive:
0.5?

regards
Agni


Yeah it works but you said you want 0.5.
The output with your solution 1.0/2.0 is 0.500000.That why I gave you my solution.
Else with your solution you can do like this select cast(1.0/2.0 as real) to give output as 0.5

Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-01-28 : 03:21:47
See http://www.sqlteam.com/Forums/topic.asp?TOPIC_ID=95948



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-01-28 : 03:56:45
http://sqlblogcasts.com/blogs/madhivanan/archive/2008/01/16/beware-of-implicit-conversions.aspx

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -