Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old February 11th, 2004, 02:04 PM
Authorized User
 
Join Date: Jan 2004
Location: Frederick, MD, USA.
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
Reply With Quote
  #2 (permalink)  
Old February 11th, 2004, 02:41 PM
Authorized User
 
Join Date: Jan 2004
Location: Frederick, MD, USA.
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.
Reply With Quote
  #3 (permalink)  
Old February 11th, 2004, 02:57 PM
Authorized User
 
Join Date: Jan 2004
Location: Frederick, MD, USA.
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...
Reply With Quote
  #4 (permalink)  
Old February 11th, 2004, 04:00 PM
joefawcett's Avatar
Wrox Author
Points: 9,763, Level: 42
Points: 9,763, Level: 42 Points: 9,763, Level: 42 Points: 9,763, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Exeter, , United Kingdom.
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
Reply With Quote
  #5 (permalink)  
Old February 11th, 2004, 05:01 PM
Authorized User
 
Join Date: Jan 2004
Location: Frederick, MD, USA.
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!
Reply With Quote
  #6 (permalink)  
Old February 12th, 2004, 09:43 AM
joefawcett's Avatar
Wrox Author
Points: 9,763, Level: 42
Points: 9,763, Level: 42 Points: 9,763, Level: 42 Points: 9,763, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Exeter, , United Kingdom.
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
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 07:04 PM.


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