Wrox Programmer Forums

Need to download code?

View our list of code downloads.

| FAQ | Members List | Search | Today's Posts | Mark Forums Read
Classic ASP Databases Discuss using ASP 3 to work with data in databases, including ASP Database Setup issues from the old P2P forum on this specific subtopic. See also the book forum Beginning ASP.NET Databases for questions specific to that book. NOT for ASP.NET 1.0, 1.1, or 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Databases 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
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old June 9th, 2003, 10:05 PM
Friend of Wrox
 
Join Date: Jun 2003
Location: Oklahoma City, Oklahoma, USA.
Posts: 249
Thanks: 0
Thanked 0 Times in 0 Posts
Default Get Counts

Hello
Can somebody tell me a way to get this to work. I have one table with my Store Name and ID's and I have another table for Orders and OrderStatis. This will either be Pending or Filled, they are joined together by the StoreID. What I need is for each store to know the Count for both Pending orders and Filled orders. The database is Access.

I have tried using a Union Count statement but get errors, I'm thinking I may need to use something else but cannot figure out what.

strSQL = "SELECT StoreID, StoreName FROM Stores " &_
            "UNION SELECT COUNT DISTINCT(OrderPending) AS Pending FROM Orders WHERE StoreNo = OrdersStoreNo AND Statis = 'Pending' " &_
            "UNION SELECT COUNT DISTINCT(OrderPending) AS Filled FROM Orders WHERE StoreNo = OrdersStoreNo AND Statis = 'Filled' ;"

Any help or guidance is greatly appreciated.
Mike
__________________
Peace
Mike
http://www.eclecticpixel.com
Reply With Quote
  #2 (permalink)  
Old June 9th, 2003, 10:28 PM
Authorized User
 
Join Date: Jun 2003
Location: London, , United Kingdom.
Posts: 21
Thanks: 0
Thanked 0 Times in 0 Posts
Default

If you are having troubles with your joins, why not try building two seperate recordsets...

Code:
strSQLP = "SELECT DISTINCT Count(*) AS PENDING " _
        & "FROM Orders " _
        & "WHERE StoreNo = OrdersStoreNo " _
        & "AND Statis = 'Pending'"

strSQLF = "SELECT DISTINCT Count(*) AS FILLED" _
        & "FROM Orders " _
        & "WHERE StoreNo = OrdersStoreNo " _
        & "AND Statis = 'Filled'"
Another way under ASP would be like this...

Code:
strSQL = "SELECT DISTINCT * FROM " _
       & "WHERE StoreNo = OrdersStoreNo"

SET Rs = Server.CreateObject("AODODB.RecordSet")
Rs.Open strSQL, objConn

Dim Pending, Filled
Pending = 0
Filled = 0

WHILE NOT Rs.EOF
  IF Rs("Statis") = "Pending" THEN Pending = Pending + 1
  IF Rs("Statis") = "Filled" THEN Filled = Filled + 1
  Rs.MoveNext
WEND

IF NOT Rs.BOF THEN Rs.MoveFirst
I hope this helps or maybe gives you a few more ideas as to what your problem might be.

Cheers!
Reply With Quote
  #3 (permalink)  
Old June 9th, 2003, 10:52 PM
Friend of Wrox
 
Join Date: Jun 2003
Location: Oklahoma City, Oklahoma, USA.
Posts: 249
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks for the ideas my brain feels better. I thought of the 2 recordsets but was hoping there was a more efficient way of doing it with one statement, I'll use your second suggestion, again thanks the help.
Reply With Quote
  #4 (permalink)  
Old June 10th, 2003, 12:45 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: Sydney, NSW, Australia.
Posts: 111
Thanks: 0
Thanked 0 Times in 0 Posts
Default

You can do this in a single SQL statement. Just use:

SELECT
   StoreID,
   StoreName,
   OrderStatus,
   COUNT(*)
FROM
   Stores
INNER JOIN
   Orders
ON
   Stores.StoreID = Orders.StoreID
GROUP BY
   StoreID, StoreName, OrderStatus
ORDER BY
   StoreID, OrderStatus DESC

Cheers
Ken

www.adOpenStatic.com
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
Adding COUNTs fizzerchris SQL Server 2005 3 February 6th, 2007 05:16 PM
Join for two different counts on same view thenoseknows SQL Server 2000 0 January 21st, 2007 06:37 PM
Getting Counts hugh@kmcnetwork.com SQL Language 2 October 27th, 2004 04:01 PM
join two counts field erin SQL Language 2 October 29th, 2003 04:50 AM
How to HavePrint Counts amar Pro VB 6 0 July 13th, 2003 10:05 AM



All times are GMT -4. The time now is 07:53 AM.


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