Counting expression doesn't work when sorted by count - Access 200



The following SQL script works fine:

SELECT [Works_number] & [BT_SCP] & [Test_code_2] AS PSCP, Count([PSCP]) AS
Expr1
FROM Main
GROUP BY [Works_number] & [BT_SCP] & [Test_code_2];

However the following SQL script doesn't work. The difference in the two
scripts is the added last line ORDER BY:

SELECT [Works_number] & [BT_SCP] & [Test_code_2] AS PSCP, Count([PSCP]) AS
Expr1
FROM Main
GROUP BY [Works_number] & [BT_SCP] & [Test_code_2]
ORDER BY Count([PSCP]) DESC;

When I try to run the second script, Access comes back with an 'Enter
parameter value' request for PSCP.

I rarely build my queries in SQL as I don't come from an SQL background. I
usually build them in design view. In design view the first query is as
follows:

Field - PSCP: [Works_number] & [BT_SCP] & [Test_code_2]
Total - Group By

Field - Expr1: [PSCP]
Total - Count

and the second query is identical except for the sort, as follows:

Field - PSCP: [Works_number] & [BT_SCP] & [Test_code_2]
Total - Group By

Field - Expr1: [PSCP]
Total - Count
Sort - Descending

Hoping someone can point out my error. I'm guessing my problem lies in
incorrectly assuming the design grid is producing the SQL code I think it
should.

Thanks,
Pat

.



Relevant Pages

  • Re: Use GUID instead of AutoInc
    ... how is the field shown in the Access GUI when you open the ... table created by SQL in design ... Do you create the database using a SQL script ... I can use the datatype "uniqueidentifier" just fine in my SQL script. ...
    (borland.public.delphi.database.ado)
  • Re: SQL
    ... > If you design right, you can *shift* much behavior to being data and ... > SQL is close to being Turing Complete. ... It is a bad habit of yours. ... If you're seriously suggesting that CRUD applications are equal ...
    (comp.object)
  • Re: Access Rewrites SQL Incorrectly
    ... My understanding is that a Group By enforces a sort order, ... So are you saying that Access Jet is wrong in its handling of the SQL? ... Access design grid reinterprets the SQL differently. ...
    (comp.databases.ms-access)
  • Re: Object-oriented thinking in SQL context?
    ... away from arrays and other non-OO data structures associated ... SQL is constrained to 'trivial' arrays. ... Design: Logical Design", 4th edition. ... Something analogous happens with database design. ...
    (comp.databases.theory)
  • Re: Last 30 days in Query
    ... In order to do the last 30 entries, you would have to first decide on an order to sort your data. ... If you are asking "Where do I enter these SQL statements at?", you need to enter them in SQL view of the query. ... Design view, Datasheet view, and SQL view. ...
    (microsoft.public.access.queries)