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.
| Author |
Topic |
|
mj
Starting Member
25 Posts |
Posted - 2002-07-05 : 10:15:14
|
| Here is the total code for my query (its short) followed by results. What I can't figure out, is why it is not doing the division correctly. I attribute this mostly to my ignorance. I appreciate any help with this.declare @TotalDeals intSelect @TotalDeals = count(issueNo) FROM dbo.DEALWHERE borrowerstate = 'IL' and moodys is not null--Print @TotalDealsSELECT moodys, count(moodys)as MoodysCount , (count(moodys)/@TotalDeals) as MoodysPerc, @TotalDealsFROM dbo.DEALWHERE borrowerstate = 'IL' and moodys is not nullGROUP BY moodyscolumn headers are shown in the query above 1 0 53A1/VMIG 1 1 0 53A1/VMIG-1 1 0 53Aa1 1 0 53aa3/VMIG 1 0 53Aa3/VMIG1 1 0 53Aaa 5 0 53Baa 1 0 53Baa1 1 0 53Baa2 1 0 53MIG 1/VMIG 1 2 0 53NR 36 0 53Ser C: A1/VMIG1 1 0 53 |
|
|
Kevin Snow
Posting Yak Master
149 Posts |
Posted - 2002-07-05 : 10:24:45
|
| @totaldeals is an integer.You need to be aware that INTEGER division results in an INTEGER result. Fractions are droppedIf you want the result of a division to be 'real', you need to cast the values involved to a type that supports decimals.ie. cast(count(moodys) as numeric)/cast(@TotalDeals as Numeric) as MoodysPerc |
 |
|
|
|
|
|