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 2000 Forums
 SQL Server Development (2000)
 Dividing a big number by a little number equals zero!

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2002-03-29 : 09:35:45
Tim writes "SQL Server 2000 Personal
Win 2000 Pro

Sorry but here's an easy one (which I can't figure out)..

When getting the product of a fraction (i.e. SET x = 3/4) all that ever comes out is a big fat zero regardless of data type. What's going on???

Thanks

Tim"

graz
Chief SQLTeam Crack Dealer

4149 Posts

Posted - 2002-03-29 : 09:35:45
Why don't you post your code?
Go to Top of Page

billsox
Yak Posting Veteran

74 Posts

Posted - 2002-03-29 : 10:38:43
SQL Server is treating 3 and 4 as whole numbers. To get the answer you desire, try the following code:

DECLARE @X DECIMAL(3, 2)
SELECT @X = CAST(3 AS DECIMAL(3, 2)) / 4
SELECT @X

Or...

DECLARE @X DECIMAL(3, 2)
SELECT @X = 3 / (4 * 1.0)
SELECT @X

Both of these methods will force SQL to treat @X as a value with decimal places. Hope this helps.

Bill
Go to Top of Page
   

- Advertisement -