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
 divide two numbers

Author  Topic 

paritosh
Starting Member

42 Posts

Posted - 2012-01-18 : 04:39:15
i have a problem :-


when divided two numbers

select 15/10

answer is 1

but i want exact answer

pls give answer

thanks in advance

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2012-01-18 : 04:44:11
select 15/10.0


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

Transact Charlie
Master Smack Fu Yak Hacker

3451 Posts

Posted - 2012-01-18 : 04:50:50
webfred is right but you might want to know the reason why.....

if you divide 2 integer values then you use integer division. So to get the answer you want then you use FLOAT or DECIMAL/NUMERIC types which result in non integer division.

so if you wanted to divide 2 integers from variables or column values you need to CAST or CONVERT one of the values to a FLOAT or DECIMAL.

Charlie
===============================================================
Msg 3903, Level 16, State 1, Line 1736
The ROLLBACK TRANSACTION request has no corresponding BEGIN TRANSACTION
Go to Top of Page
   

- Advertisement -