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

GROUP BY clause is missing or invalid 1

Status
Not open for further replies.

Niki_S

Programmer
Jun 4, 2021
232
LK
When I run my code it says "GROUP BY clause is missing or invalid". What is the issue in this code?
Code:
SELECT nStylecode,cAccountNo,cContract,cStyleNumber as Style,cLotName,cCategory,nCiQty,cShipFty,cColorName,cShipMode,dEx_dte,dindc_dte,;
cDestination as Destinatn,cPoNo,cSeason,000000000 as Delvr_Pcs,000000000 as nqty FROM _DelClr GROUP BY cColorName INTO Dbf C:\Tempfiles\_DelDtl

Thank you
 
The rule states that, whenever you have a query that involves grouping, each field in the result set (that is, each expression immediately following the word SELECT) must be either: (i) one of the fields involved in the grouping; or (ii) an aggregate expression, such as SUM(), AVG(), COUNT(), etc.

Your SELECT statement does not follow that rule, hence the error.

By the way, this is not a Foxpro rule. It applies to SQL generally.

There is a good reason for this rule. Your result set will contain one record for each cColorName. That's the whole point of grouping. So how would the query know which nStylecode, cAccountNo, etc. to put into that record?

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
You can get around the requirement that Mike stated by doing this:

Code:
SET ENGINEBEHAVIOR 70
* Do your SQL SELECT here
SET ENGINEBEHAVIOR 90

The older engine allowed the malformed GROUP BY clause, which often has valid utility but is technically data-incorrect.

--
Rick C. Hodgin
 
What Rick says is correct. But keep in mind that, if the various fields following the word SELECT (nStylecode, cAccountNo, etc.) are not all unique within each group, the results will be somewhat meaningless. That's why the rule exists. But give it a try, by all means.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Thank you all for the helps. I fixed it [bigsmile].
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top