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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Aggregate function/groupby clause error

Status
Not open for further replies.

redeemasp

Programmer
Jun 1, 2004
63
GB
Hi there

I keep getting a

'dbo.AMGR_Client.Contact_Number is invalid in the select list because it is not contained in an aggregate funtion or a GROUP BY clause.'

I want to count all the client names in all of the dbo_ORC_get_G01AccountStatus.Description but get the above error. Any ideas

code:


SELECT dbo.AMGR_Client.Contact_Number, dbo.AMGR_Client.Name, dbo_ORC_get_G09CoreIndustry.Client_Id,
COUNT(dbo_ORC_get_G01AccountStatus.Description) AS Expr1, dbo_ORC_get_G01AccountStatus.Description AS Expr2
FROM dbo.AMGR_Client INNER JOIN
dbo_ORC_get_G09CoreIndustry ON dbo.AMGR_Client.Client_Id = dbo_ORC_get_G09CoreIndustry.Client_Id INNER JOIN
dbo_ORC_get_G01AccountStatus ON dbo.AMGR_Client.Client_Id = dbo_ORC_get_G01AccountStatus.Client_Id INNER JOIN
dbo_ORC_get_G04ORCDivisions ON dbo.AMGR_Client.Client_Id = dbo_ORC_get_G04ORCDivisions.Client_Id
WHERE (dbo.AMGR_Client.Contact_Number = 0)
GROUP BY dbo_ORC_get_G01AccountStatus.Description
 
If you have it in the SELECT list and it is not an aggregate function, it need to be in the GROUP BY clause

Code:
SELECT     dbo.AMGR_Client.Contact_Number, dbo.AMGR_Client.Name, dbo.ORC_get_G09CoreIndustry.Client_Id,
                      COUNT(dbo.ORC_get_G01AccountStatus.Description) AS Expr1, dbo.ORC_get_G01AccountStatus.Description AS Expr2
FROM         dbo.AMGR_Client INNER JOIN
                      dbo.ORC_get_G09CoreIndustry ON dbo.AMGR_Client.Client_Id = dbo.ORC_get_G09CoreIndustry.Client_Id INNER JOIN
                      dbo.ORC_get_G01AccountStatus ON dbo.AMGR_Client.Client_Id = dbo.ORC_get_G01AccountStatus.Client_Id INNER JOIN
                      dbo.ORC_get_G04ORCDivisions ON dbo.AMGR_Client.Client_Id = dbo.ORC_get_G04ORCDivisions.Client_Id
WHERE     (dbo.AMGR_Client.Contact_Number = 0)
GROUP BY dbo.AMGR_Client.Contact_Number, dbo.AMGR_Client.Name, dbo.ORC_get_G09CoreIndustry.Client_Id,
 dbo.ORC_get_G01AccountStatus.Description

Programming today is a race between software engineers striving to build better and bigger idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. - Rick Cook (No, I'm not Rick)

zen.gif
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top