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!

MS Query SQL problem

Status
Not open for further replies.

daggers

Technical User
Sep 10, 2002
13
GB
Hi,

If I have the following code in a SQL statement in MS Query:

...WHERE table_x.variable_y='A'
GROUP BY table_x.variable_z....

and run it, it appears to ignore the first line and groups the entire content of table_x rather than grouping the content of table_x and restricting the grouped content to where variable_y='A'. Is there any way of doing this?

Thanks.
 
This works for me

Code:
SELECT cust.so, Count(cust.no)
FROM pdunity.dbo.cust cust
WHERE (cust.status<>'active')
GROUP BY cust.so

Do you have your aggregate functions set up correctly...

Do you get the right number of records if you exclude the GROUP BY statement?

Will
 
mmh, that code looks ok to me.. it may be a silly question, but have you checked that there are records ='A' in table_x? and that the name is called variable_y?

maybe try using
Code:
...WHERE table_x.variable_y LIKE 'A'
   GROUP BY table_x.variable_z....

even though the = should suffice..maybe access is just being access. if that still doesnt work maybe try doing it through Access, i.e. set 'A' in the Criteria row and then have Sort by variable_z



 
WillRiley:
If I exclude the GROUP BY statement, I get the right number of records for the criteria table_x.variable_y='A'...I am just at a loss to show those records aggregated by variable_z as well.

How do I set up aggregate functions? 'Help' is no use..

 
I have worked out what the problem is...

The first line of code should have been

SELECT SUM(table_x.variable_z) AS 'Total'

rather than

SELECT table_x.variable_z

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top