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 13th, 2004, 10:10 AM
demp225 demp225 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2004
Posts: 5 demp225 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
display the number of results found for a subcategory

Hello,

I am working on a project that displays images. Before you can get to the image, you have to select a category that the image may be in. After that, you select the sub categories. I am trying to display a count of the number of records that the subcategories contain. Here is an example:

The user can make a selection from the categories listed below:

Geographic Area
Time Period
Topic
Record Type


If the user selects time period, he/she is taken to a list of subcategories. I would like to display the subcategories with a count of the number of records that will be displayed if it is selected. Listed below is an example of what this would look like:

Colonial (10) -----the number in parenthesis is the number of records that will be displayed if selected------
Gilded Age (12)
Revolutionary (9)
Progressive Era (22)


Is there a way to display the number in parenthesis using ASP.Net and SQL Server 2000? Any clues will be greatly appreciated.

Thanks

Reply With Quote
  #2  
Old October 13th, 2004, 10:17 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
You have to run a SQL statement for each sub-category:
SELECT COUNT(*) FROM...
with the rest being exactly what you use for a SQL statement on the next page.

Hope that helps.

Reply With Quote
  #3  
Old October 13th, 2004, 10:21 AM
r937's Avatar
r937 r937 is offline
SQL Consultant
Click here for more information.
 
Join Date: Feb 2003
Location: Toronto Canada
Posts: 17,653 r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level) 
Time spent in forums: 1 Month 3 Weeks 6 Days 12 h 34 m 33 sec
Reputation Power: 981
actually, running one query for all sub-categories is better than running a query for each subcategory
Code:
select subcategory
     , count(*) as images
  from yourtable
group 
    by subcategory
__________________
r937.com | rudy.ca

Reply With Quote
  #4  
Old October 22nd, 2004, 10:52 AM
demp225 demp225 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2004
Posts: 5 demp225 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
help again display the number of results found for a subcategory

Thanks to both of you for your help. I have used the query you provided as a starting point. here is my query:


Select record_name, count(record_name)as rc_count from record_type, vv_entry
where record_name *= vv_entry.record_type
group by record_name


These are the results that I am getting:

record_name rc_count
Audio Recording 1
Document 10
Map 2
Microfilm 1
Other 1
Photograph 5
Plan 1
Video Recording 1
Visual Image 4


The problem that I have now is that the rc_count values that are 1 should be 0. Is there any way that I can use an If statement that will change all of the 1s to 0s?

Your help is greatly appreciated

Quote:
Originally Posted by r937
actually, running one query for all sub-categories is better than running a query for each subcategory
Code:
select subcategory
     , count(*) as images
  from yourtable
group 
    by subcategory

Reply With Quote
  #5  
Old October 22nd, 2004, 12:56 PM
demp225 demp225 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2004
Posts: 5 demp225 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
help again display the number of results found for a subcategory

Thanks to both of you for your help. I have used the query you provided as a starting point. here is my query:


Select record_name, count(record_name)as rc_count from record_type, vv_entry
where record_name *= vv_entry.record_type
group by record_name


These are the results that I am getting:

record_name rc_count
Audio Recording 1
Document 10
Map 2
Microfilm 1
Other 1
Photograph 5
Plan 1
Video Recording 1
Visual Image 4


The problem that I have now is that the rc_count values that are 1 should be 0. Is there any way that I can use an If statement that will change all of the 1s to 0s?

Your help is greatly appreciated

Reply With Quote
  #6  
Old October 22nd, 2004, 01:53 PM
swampBoogie swampBoogie is offline
Contributing User
Dev Shed Intermediate (1500 - 1999 posts)
 
Join Date: Jan 2003
Location: Paris Uppland
Posts: 1,773 swampBoogie User rank is Sergeant Major (2000 - 5000 Reputation Level)swampBoogie User rank is Sergeant Major (2000 - 5000 Reputation Level)swampBoogie User rank is Sergeant Major (2000 - 5000 Reputation Level)swampBoogie User rank is Sergeant Major (2000 - 5000 Reputation Level)swampBoogie User rank is Sergeant Major (2000 - 5000 Reputation Level)swampBoogie User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 2 Weeks 4 Days 14 h 30 m 5 sec
Reputation Power: 37
Code:
Select record_name, count(record_type)as rc_count 
from record_type left join vv_entry
on record_name = vv_entry.record_type
group by record_name

Reply With Quote
  #7  
Old October 22nd, 2004, 02:51 PM
demp225 demp225 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2004
Posts: 5 demp225 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Thank you very much. This worked perfectly. Now, I am going to research the left joins.

Thanks again


Quote:
Originally Posted by swampBoogie
Code:
Select record_name, count(record_type)as rc_count 
from record_type left join vv_entry
on record_name = vv_entry.record_type
group by record_name

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesMS SQL Development > display the number of results found for a subcategory


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 4 hosted by Hostway