Wrox Programmer Forums
|
Access Discussion of Microsoft Access database design and programming. See also the forums for Access ASP and Access VBA.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 11th, 2004, 02:04 PM
Authorized User
 
Join Date: Jan 2004
Posts: 43
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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
 
Old February 11th, 2004, 02:41 PM
Authorized User
 
Join Date: Jan 2004
Posts: 43
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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.
 
Old February 11th, 2004, 02:57 PM
Authorized User
 
Join Date: Jan 2004
Posts: 43
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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...
 
Old February 11th, 2004, 04:00 PM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

Surely you just need:
Code:
SELECT [type], SUM(hits)
FROM tblCounter
GROUP BY [type]
?

--

Joe
 
Old February 11th, 2004, 05:01 PM
Authorized User
 
Join Date: Jan 2004
Posts: 43
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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!
 
Old February 12th, 2004, 09:43 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

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





Similar Threads
Thread Thread Starter Forum Replies Last Post
Simple query question ltblue14 Access 3 July 16th, 2006 02:10 PM
Simple Query Need Help ~Bean~ SQL Language 2 June 27th, 2005 11:22 AM
Simple Tomcat Query? Baztec Apache Tomcat 0 January 13th, 2004 11:38 PM
Simple Query/Display ABATES VS.NET 2002/2003 1 August 10th, 2003 05:54 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.