Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

need help with select statement to calculate sum

Status
Not open for further replies.

maxf

Programmer
Oct 2, 2002
25
US
Im trying to calculate the difference between two columns. The statement im using is:

Select course_name, sum(no_players-players_booked) as no from TEE_TIMES

When I try this statement I get the error message:

Error Type:
Microsoft OLE DB Provider for SQL Server (0x80040E14)
Column 'tee_times_for_sale.ID' is invalid in the select list because it is not contained in an aggregate function and there is no GROUP BY clause.
/golf/csadmin/no.asp, line 14

How can I accomplish this?

Thanks for any help
 
1) The query does a SUM but I don't see any difference calculation.

2) The error message doesn't fit with code you posted. The column named in the error message, tee_times_for_sale.ID, is not in the query. It would make sense if the error message said "Tee_Times.course_name is not contained in an aggregate function and there is no GROUP BY clause."

3) The query you posted is syntactically incorrect. It has an AGGREGATE function, SUM, but no GROUP BY clause. Modify as follows.

Select course_name, sum(no_players-players_booked) as no
From TEE_TIMES
Group By course_name
Terry L. Broadbent - DBA
SQL Server Page:
If you want to get the best answer for your question read faq183-874.
 
i got it working. i needed the group by clause as you suggested.

thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top