p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   Access (http://p2p.wrox.com/forumdisplay.php?f=18)
-   -   Simple query errors (http://p2p.wrox.com/showthread.php?t=9254)

Justine February 11th, 2004 02:04 PM

Simple query errors
 
This seems simple enough but I can't find where I'm going wrong.

I want to run a query that sums the number of hits for each type of site. The table has a type field and a hits field so all I need to do is sum them up and sort by type. But I'm getting the following error.

ADO error: Line 3: Incorrect Syntax near '100'.

Here is the sql for my query.

SELECT TOP 100 PERCENT Type, SUM(Type) AS CountofHits
FROM Web_Code08.tbl_counter
GROUP BY Type

I haven't done much in Access 2002 so this might be just a simple error on my part. Any help would be appreciated.

Justine

Justine February 11th, 2004 02:41 PM

Well, as I suspected it was a major oversight on my part. I figured it out. Thank you anyway!

Access 2002 just inserts the TOP 100 PERCENT thing which messes it up. So I just took it out and used the database.table.field syntax.

Justine February 11th, 2004 02:57 PM

Alright, I spoke too soon. Now I'm having the same problem with another query. Access 2002 insists upon inserting the TOP 100 PERCENT thing and I can't figure out why. This time I just want to select all fields in a table. But it gives me the error mentioned above and inserts the TOP 100 PERCENT.

SELECT TOP 100 PERCENT Web_Code08.tbl_Reports.*
FROM Web_Code08.tbl_Reports
WHERE (FY = 2004)
ORDER BY Order_Number

Thanks in advance...

joefawcett February 11th, 2004 04:00 PM

Surely you just need:
Code:

SELECT [type], SUM(hits)
FROM tblCounter
GROUP BY [type]

?

--

Joe

Justine February 11th, 2004 05:01 PM

Yeah, I got that working. But why does Access 2002 insist on inserting the TOP 100 Percent thing for select all queries? And how does this work?

For example, it turns this

SELECT Web_Code08.tbl_Reports.*
FROM Web_Code08.tbl_Reports
WHERE (FY = 2004)
ORDER BY Order_Number

Into this

SELECT TOP 100 PERCENT Web_Code08.tbl_Reports.*
FROM Web_Code08.tbl_Reports
WHERE (FY = 2004)
ORDER BY Order_Number

I appreciate your help!

joefawcett February 12th, 2004 09:43 AM

Perhaps it's trying to be ansi compliant. In theory you can't have an ORDER BY statement on a view unless the view uses the TOP keyword. To get around this it adds TOP 100 PERCENT to the statement.

--

Joe


All times are GMT -4. The time now is 05:00 AM.

Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.