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
 Expression does not return decimal value!

Author  Topic 

smartbhatt
Starting Member

2 Posts

Posted - 2007-11-29 : 08:33:02
Hello,
Below statement in tsql returns int value (0).

SELECT 5/10

How to force it to return decimal value (0.5)?
I tried following but it did not help me
1) SELECT Convert(numeric(7,2),5/10)
2) Declare @Var1 numeric(7,2)
SET @Var1 = SELECT Convert(numeric(7,2),5/10)
SELECT @Var1

Thanks.

jhocutt
Constraint Violating Yak Guru

385 Posts

Posted - 2007-11-29 : 08:35:00
select 5/10.0


"God does not play dice" -- Albert Einstein
"Not only does God play dice, but he sometimes throws them where they cannot be seen."
-- Stephen Hawking
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-11-29 : 08:40:03
<<
SELECT Convert(numeric(7,2),5/10)
>>

Note that the convertion is done after processing 5/10 (which by default results to 0)
So you need to convert either of the operand to be numeric

SELECT 5/Convert(numeric(7,2),10)


Madhivanan

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

smartbhatt
Starting Member

2 Posts

Posted - 2007-11-29 : 08:42:56
Thank you for the reply with explanation.
Go to Top of Page
   

- Advertisement -