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 |
|
zavier
Yak Posting Veteran
50 Posts |
Posted - 2003-12-15 : 11:34:09
|
| Hello AllI have a simple question. I have the following in a stored procedure:DECLARE @T1COUNT INTDECLARE @T2COUNT INTDECLARE @RATIO DECIMALSELECT @T1COUNT=COUNT(*) FROM #TABLE1SELECT @T2COUNT=COUNT(*) FROM #TABLE2SET @RATIO = @T1COUNT/@T2COUNTPRINT @RATIOThis doesn't seem to work. The variables @T1COUNT and @T2COUNT have the correct numbers in them but when I do the division the @RATIO variable contains zero. I think my syntax is incorrect. If anyone can lend a hand I would appreciate it. Thanks |
|
|
SamC
White Water Yakist
3467 Posts |
Posted - 2003-12-15 : 11:43:04
|
| Integer division?5 / 10 = 0Gotta convert one or both integers to real.Here's a cheat:set @ratio = 1.0 * @T1count / @T2countHere's a better solutionset @ratio = CAST(@T1count AS DECIMAL) / CAST(@T2count AS DECIMAL)I'm not sure what the default precision is on DECIMAL, so I always specify it like:CAST(@T1count AS DECIMAL(5,2)) |
 |
|
|
zavier
Yak Posting Veteran
50 Posts |
Posted - 2003-12-15 : 12:08:14
|
| Thanks very much. I knew it was something I was overlooking. |
 |
|
|
|
|
|