Re: simple math question
From: Kalen Delaney (replies_at_public_newsgroups.com)
Date: 09/02/04
- Next message: Rob: "Re: dbcc output to a file?"
- Previous message: Savas Ates: "Re: simple math question"
- In reply to: ChrisR: "Re: simple math question"
- Next in thread: Adam Machanic: "Re: simple math question"
- Messages sorted by: [ date ] [ thread ]
Date: Thu, 2 Sep 2004 08:37:44 -0700
Chris
The issue is that SQL Server thinks it is dividing two integers. When both
operands are integers, then integer division is performed, then any
remainder is discarded.
You have to force one of the operands to be NOT an integer, any type that
can carry decimal digits might work for you.
For a integer constant, you can change it to non-integer by just adding a
decimal point.
So SQL Server will see this:
count(*)/12. as dividing an integer by a decimal and you will get decimal
digits. Maybe more than you want. :-)
If you want a specific number of digits, you will have to use convert to a
type that has that number of digits. Please read about the decimal and
numeric types in the Books Online
use pubs
select convert(numeric(10,2), count(*)/12.)
from titles
-- HTH ---------------- Kalen Delaney SQL Server MVP www.SolidQualityLearning.com "ChrisR" <anonymous@discussions.microsoft.com> wrote in message news:0c2201c49100$afe192c0$a401280a@phx.gbl... > Thanks guys for the speedy response. If Im doing a count > what do I do? > > select LastYear= > count(*)/ 12 > from bla bla > > Do I need to set the count to a parameter. I tried it and > its not working too well. > > > >-----Original Message----- > >explicitly use the period ( . ) after the 1 for a type > conversion, i.e., > >select 1./3 > > > >hth > >Eric > > > > > > > >ChrisR wrote: > >> sql2k sp3 > >> > >> select (1 / 3) > >> > >> gives me the result of 0. > >> > >> I dont need precise results, but would at least like to > >> see .33. How can this be accomplished? > >> > >> TIA, ChrisR > > > > > >. > >
- Next message: Rob: "Re: dbcc output to a file?"
- Previous message: Savas Ates: "Re: simple math question"
- In reply to: ChrisR: "Re: simple math question"
- Next in thread: Adam Machanic: "Re: simple math question"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|