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 |
|
AndyC
Yak Posting Veteran
53 Posts |
Posted - 2004-10-25 : 09:33:40
|
| I am compiling a table of data for a golf competitionEach winning match is worth 1 point, each tied game 0.5 pointsIt may not be the most elegant method but I can get the number of wins and draws by a player/team as followsCOUNT(CASE WHEN (matches.winner = 'US')THEN 1 END )/4 as WinCOUNT(CASE WHEN (matches.winner = 'Halved')THEN 1 END )/4 as TieHowever when I try to obtain the points total thusCOUNT(CASE WHEN (matches.winner = 'US')THEN 1 END )/4+ COUNT(CASE WHEN (matches.winner = 'Halved')THEN 1 END )/8 as Pointsthe result gets rounded down. For instance 2 wins and 3 ties results in 3 points rather than 3.5I have played arounf with CAST and CONVERT but either end up with errors or the same conclusionAndrew Clarkwww.majorleaguecharts.com |
|
|
spirit1
Cybernetic Yak Master
11752 Posts |
Posted - 2004-10-25 : 09:42:21
|
try it like this:cast(COUNT(CASE WHEN (matches.winner = 'US')THEN 1 END ) as decimal(9,4))/4 as Wincast(COUNT(CASE WHEN (matches.winner = 'Halved')THEN 1 END ) as decimal(9,4))/4 as Tieandcast(COUNT(CASE WHEN (matches.winner = 'US')THEN 1 END ) as decimal(9,4))/4 + cast(COUNT(CASE WHEN (matches.winner = 'Halved')THEN 1 END ) as decimal(9,4))/8 as PointsGo with the flow & have fun! Else fight the flow |
 |
|
|
|
|
|