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 |
|
tonzo1883
Starting Member
12 Posts |
Posted - 2008-03-29 : 03:38:11
|
| Hi,I wonder if anyone can help. All I am trying to do is combine three SQL SELECT queries into one. They are:SELECT COUNT(ISNULL(Result, 0)) AS Win FROM Games WHERE (CurrentSeason = 'True') AND Result = 'Win'AND ([MatchType] = @MatchType)SELECT COUNT(ISNULL(Result, 0)) AS Lose FROM Games WHERE (CurrentSeason = 'True') AND Result = 'Lose'AND ([MatchType] = @MatchType)SELECT COUNT(ISNULL(Result, 0)) AS Draw FROM Games WHERE (CurrentSeason = 'True') AND Result = 'Draw'AND ([MatchType] = @MatchType)As you can see they are all doing pretty much the same thing. I have experimented by using GROUP and HAVING but end up with no results. Sorry if this is obvious but I am new to SQL! Many Thanks |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-03-29 : 03:41:37
|
| [code]SELECT COUNT(CASE WHEN Result='Win' THEN ISNULL(Result, 0) END) AS Win,COUNT(CASE WHEN Result='Lose' THEN ISNULL(Result, 0) END) AS Lose,COUNT(CASE WHEN Result='Draw' THEN ISNULL(Result, 0) END) AS Draw FROM Games WHERE (CurrentSeason = 'True') AND Result IN ('Win','Lose','Draw') AND ([MatchType] = @MatchType)[/code] |
 |
|
|
tonzo1883
Starting Member
12 Posts |
Posted - 2008-03-29 : 03:45:26
|
| That's works great.I really appreciate your help.Many Thanks |
 |
|
|
|
|
|