Web Wiz - Green Windows Web Hosting

  New Posts New Posts RSS Feed - SQL Syntax - COUNT(*)
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

SQL Syntax - COUNT(*)

 Post Reply Post Reply Page  12>
Author
faca5 View Drop Down
Mod Builder Group
Mod Builder Group


Joined: 30 July 2003
Location: Slovenia
Status: Offline
Points: 187
Post Options Post Options   Thanks (0) Thanks(0)   Quote faca5 Quote  Post ReplyReply Direct Link To This Post Topic: SQL Syntax - COUNT(*)
    Posted: 12 December 2005 at 6:03am
Very easy question. What is wrong? Why I get "-1" If table have some record?
 

Dim aaaa
Set adoCon = Server.CreateObject("ADODB.Connection")

adoCon.Open = "Provider=Microsoft.Jet.OLEDB.4.0;

Data Source=" & Server.MapPath("testing.mdb")

Set testing = Server.CreateObject("ADODB.Recordset")

strSQL = "SELECT COUNT(*) FROM table;"
 
testing.Open strSQL, adoCon
 

 
 aaaa = testing.RecordCount

 Response.Write aaaa
 
 
testing.Close
Set testing = Nothing
Set adoCon = Nothing


Edited by faca5 - 12 December 2005 at 6:07am
Back to Top
ljamal View Drop Down
Mod Builder Group
Mod Builder Group


Joined: 16 April 2003
Status: Offline
Points: 888
Post Options Post Options   Thanks (0) Thanks(0)   Quote ljamal Quote  Post ReplyReply Direct Link To This Post Posted: 12 December 2005 at 11:16am
The RecordCount Method isn't supported by some cursors and it will return -1. However, your SQL statement is returning a count so use:

aaaa = testing(0)
Back to Top
jeffdaro View Drop Down
Groupie
Groupie


Joined: 15 April 2005
Status: Offline
Points: 171
Post Options Post Options   Thanks (0) Thanks(0)   Quote jeffdaro Quote  Post ReplyReply Direct Link To This Post Posted: 12 December 2005 at 11:29am
Back to Top
faca5 View Drop Down
Mod Builder Group
Mod Builder Group


Joined: 30 July 2003
Location: Slovenia
Status: Offline
Points: 187
Post Options Post Options   Thanks (0) Thanks(0)   Quote faca5 Quote  Post ReplyReply Direct Link To This Post Posted: 12 December 2005 at 1:30pm
Ok. Thanks! Smile
 
P.S. Juhu! It work! Smile


Edited by faca5 - 12 December 2005 at 1:48pm
Back to Top
faca5 View Drop Down
Mod Builder Group
Mod Builder Group


Joined: 30 July 2003
Location: Slovenia
Status: Offline
Points: 187
Post Options Post Options   Thanks (0) Thanks(0)   Quote faca5 Quote  Post ReplyReply Direct Link To This Post Posted: 12 December 2005 at 1:51pm

Another easy question.

How I can GROUP BY some argument?

strSQL = "SELECT COUNT(*) FROM table GROUP BY argument;"
 
I get "1"? It isn't correct!
Back to Top
ub3rl337ch3ch View Drop Down
Senior Member
Senior Member
Avatar

Joined: 16 February 2005
Location: Australia
Status: Offline
Points: 341
Post Options Post Options   Thanks (0) Thanks(0)   Quote ub3rl337ch3ch Quote  Post ReplyReply Direct Link To This Post Posted: 12 December 2005 at 4:59pm

http://www.w3schools.com/sql/sql_groupby.asp

the syntax seems right. I think the problem is that you have values of 'argument' like:
 
argument
xxx
yyy
yyy
zzz
zzz
zzz
zzz
 
is what you're wanting a count of where argument = zzz?
then you'll need to cycle through your recordset to get there, because the first value in the recordset will be '1' (from xxx), then '2' (from yyy) then '4' which is what you want...
 
try tacking "WHERE argument = 'zzz'" on the end there... or actually, replace the groupby with that: it'll give you the count of the specific group you want...
Back to Top
michael View Drop Down
Senior Member
Senior Member
Avatar

Joined: 08 April 2002
Location: United States
Status: Offline
Points: 4670
Post Options Post Options   Thanks (0) Thanks(0)   Quote michael Quote  Post ReplyReply Direct Link To This Post Posted: 12 December 2005 at 6:03pm
Don't do a Count(*) when you group.
Try
Select Count(argument) from table group by argument
Back to Top
faca5 View Drop Down
Mod Builder Group
Mod Builder Group


Joined: 30 July 2003
Location: Slovenia
Status: Offline
Points: 187
Post Options Post Options   Thanks (0) Thanks(0)   Quote faca5 Quote  Post ReplyReply Direct Link To This Post Posted: 13 December 2005 at 6:52am
Thanks again! Smile
Back to Top
 Post Reply Post Reply Page  12>

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.