MS SQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsDatabasesMS SQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old October 25th, 2004, 11:01 AM
annieko annieko is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2004
Location: Northampton, UK
Posts: 11 annieko User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 9 m 52 sec
Reputation Power: 0
Question Please help with the SQL COUNT statement!

I'm trying to run this SQL statement in my ASP code, sql="SELECT COUNT(*) FROM order_list WHERE ref_index='"&ref_index&"'"

The problem is, should i create a variable to store the returned integer? I tried rs_itemcount = conn.execute(sql) and then response.write(rs_itemcount.value)

But it returns with an error... any ideas how to store the integer and use it?!

thx!

Reply With Quote
  #2  
Old October 25th, 2004, 11:23 AM
bocmaxima's Avatar
bocmaxima bocmaxima is offline
Contributing User
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Aug 2004
Location: Tucson, Sonora
Posts: 1,322 bocmaxima User rank is Sergeant (500 - 2000 Reputation Level)bocmaxima User rank is Sergeant (500 - 2000 Reputation Level)bocmaxima User rank is Sergeant (500 - 2000 Reputation Level)bocmaxima User rank is Sergeant (500 - 2000 Reputation Level)bocmaxima User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 3 Days 17 h 46 m 5 sec
Reputation Power: 23
Send a message via AIM to bocmaxima
It doesn't quite work like that. Count basically becomes a field as part of your recordset.
sql="SELECT COUNT(*) AS theCount FROM order_list WHERE ref_index='"&ref_index&"'"

Then, once you open your recordset:
yourInt = rs("theCount")

That will set yourInt to the recordcount. However, this is only accessible after you run through the whole recordset.

Reply With Quote
  #3  
Old October 26th, 2004, 03:05 AM
annieko annieko is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2004
Location: Northampton, UK
Posts: 11 annieko User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 9 m 52 sec
Reputation Power: 0
Thx for the reply...

I tried, but it says "Item cannot be found in the collection corresponding to the requested name or ordinal. "

And what do you mean by running through the whole recordset? Does it mean doing all the
if rs.eof = false then
rs.movenext
end if?
I don't understand this at all it says the sql statement should return an integer but how can i get that number?!

Reply With Quote
  #4  
Old October 26th, 2004, 03:58 PM
balainfo balainfo is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2004
Posts: 6 balainfo User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Hi


I read your error message ..this will arrive when you make wrong field name...

The following script will work

sql="SELECT COUNT(*) as cnt FROM order_list WHERE ref_index='"&ref_index&"'"

Is the ref_index field is varchar or char type? If yes then ok else
you have to change the query

now

rs = cn.execute(sql)
response.write rs("cnt")
set rs = nothing
set cn = nothing


It will work definitly

Register in http://www.balainfo.com/forums/ for detailed support

Regds
Bala

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesMS SQL Development > Please help with the SQL COUNT statement!


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway
Stay green...Green IT