SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

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

spooke
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"

bitsmed
Constraint Violating Yak Guru

277 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

spooke
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  
 New 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.05 seconds. Powered By: Snitz Forums 2000