Please start any new threads on our new site at We've got lots of great SQL Server experts to answer whatever question you can come up with.

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 SQL Query Question
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Starting Member

7 Posts

Posted - 11/24/2012 :  06:17:07  Show Profile  Reply with Quote
Hi guys,

I am wanting to get a count of wins for a specific team (my_team), this team name is given by the user that is running the application... As I am only wanting to count the wins I then need to only count the rows where my_score is greater then opp_score.

For some reason my query is not working... in my mind it looks correct however that my mind wants and what SQL wants is apparently different... if anyone can help that would be great. Query below.

"SELECT COUNT(my_team) AS wins FROM matches WHERE my_team=" & team & "AND my_score > opp_score"

Aged Yak Warrior

545 Posts

Posted - 11/24/2012 :  07:30:41  Show Profile  Reply with Quote
my guess is, that team name is defined as text. also the "AND my_score ..." is pushed up against the team name - if this is correct, you're missing the surrounding aposttophes, so your query would be:
"SELECT COUNT(my_team) AS wins FROM matches WHERE my_team='" & team & "' AND my_score > opp_score"

You could have a nice overview with this query:

select my_team
      ,count(*) as wins
  from matches
 where my_score>opp_score
 group by my_team
 order by wins desc
Go to Top of Page

Starting Member

7 Posts

Posted - 11/24/2012 :  08:08:26  Show Profile  Reply with Quote
Thanks, that is working now!
Go to Top of Page
  Previous Topic Topic Next Topic  
 Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.03 seconds. Powered By: Snitz Forums 2000