Web Wiz - Green Windows Web Hosting

  New Posts New Posts RSS Feed - Calling Results from SELECT COUNT
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

Calling Results from SELECT COUNT

 Post Reply Post Reply
Author
jdumayas View Drop Down
Newbie
Newbie
Avatar

Joined: 19 February 2003
Status: Offline
Points: 16
Post Options Post Options   Thanks (0) Thanks(0)   Quote jdumayas Quote  Post ReplyReply Direct Link To This Post Topic: Calling Results from SELECT COUNT
    Posted: 10 April 2003 at 2:54pm
Hello,

I'm using the following line of code to return the number of students are registered for a course.

rs.Open "SELECT COUNT(courseID) FROM tblCourseStudentLookup WHERE courseID="&instanceNo, adoCon

I'm not getting an error with this line(it may be incorrect usage also), but I get an error when trying to use response.write to display me the number of records (students).

I was wondering if I could get any suggestion/examples regarding the syntax of both the COUNT function and getting the results to display using response.write. FYI I'm using Access 2002.

Thanks for all of your help. - Jeremy


Back to Top
Nigelo View Drop Down
Groupie
Groupie


Joined: 11 October 2002
Location: United Kingdom
Status: Offline
Points: 67
Post Options Post Options   Thanks (0) Thanks(0)   Quote Nigelo Quote  Post ReplyReply Direct Link To This Post Posted: 10 April 2003 at 3:52pm

Originally posted by jdumayas jdumayas wrote:

Hello,

I'm using the following line of code to return the number of students are registered for a course.

rs.Open "SELECT COUNT(courseID) FROM tblCourseStudentLookup WHERE courseID="&instanceNo, adoCon

As far as the SQL string is concerned, always try to use "*" with Count function as this is heavily optimised in Access using the built in Rushmore technology and will therefore speed up processing. 

Also, your code snippet appears to be missing a name for the returned result so will default to Expr1; a field name should really be enclosed in square brackets; use spaces between the quote ("), ampersand (&) and instanceNo; and terminate the SQL expression with a ";"

Your example rewritten
 rs.Open "SELECT COUNT([courseID]) As NumRecs FROM tblCourseStudentLookup WHERE courseID=" & instanceNo & ";", adoCon

Same optimised
 rs.Open "SELECT COUNT(*) As NumRecs FROM tblCourseStudentLookup WHERE courseID=" & instanceNo & ";", adoCon  

Sorry, don't have time to test it but should work

Hope this helps
Nigel
Back to Top
Bunce View Drop Down
Senior Member
Senior Member
Avatar

Joined: 10 April 2002
Location: Australia
Status: Offline
Points: 846
Post Options Post Options   Thanks (0) Thanks(0)   Quote Bunce Quote  Post ReplyReply Direct Link To This Post Posted: 11 April 2003 at 10:53pm

and so to retrieve it using Nigelo's code:

iResult = rs("NumRecs")

Cheers,
Andrew

There have been many, many posts made throughout the world...
This was one of them.
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.08
Copyright ©2001-2026 Web Wiz Ltd.


Become a Fan on Facebook Follow us on X Connect with us on LinkedIn Web Wiz Blogs
About Web Wiz | Contact Web Wiz | Terms & Conditions | Cookies | Privacy Notice

Web Wiz is the trading name of Web Wiz Ltd. Company registration No. 05977755. Registered in England and Wales.
Registered office: Web Wiz Ltd, Unit 18, The Glenmore Centre, Fancy Road, Poole, Dorset, BH12 4FB, UK.

Prices exclude VAT at 20% unless otherwise stated. VAT No. GB988999105 - $, € prices shown as a guideline only.

Copyright ©2001-2026 Web Wiz Ltd. All rights reserved.