Microsoft SQL Server
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsDatabaseMicrosoft SQL Server

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 ASP Free Forums Sponsor:
  #1  
Old July 26th, 2005, 11:35 AM
david_ste david_ste is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Posts: 13 david_ste User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 6 h 48 m 3 sec
Reputation Power: 0
stored proc looping through returned result from select

I want to use the following procedure to firstly pull in all business units associated with a business area then count the number of projects associate with all of the business units returned.

I am fairly new to stored procs and know that what I have written is not correct but I am not sure how or if I can do this.

Any help would be greatly appreciated.

CREATE PROCEDURE sp_projSplitByBusUnit AS
@busAreaId int -- Used to Pull In Bus Area Value
@busUnits -- Used to store return from first select statement
busUnitCount varchar return
BEGIN

SELECT t_bus_areas.f_bus_unit_id, t_bus_areas.f_name
FROM t_bus_units
WHERE f_bus_area_id = @busAreaId

-- Loop through returned records to pull in buiness areas

for i = 0 to uBound(@busUnits, 2)
busUnitCount & i = count *
FROM t_proj
WHERE f_bus_unit_id = @busUnits(i)
next

END

GO

Reply With Quote
  #2  
Old July 27th, 2005, 01:32 PM
blicci's Avatar
blicci blicci is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Apr 2004
Location: Philly
Posts: 351 blicci User rank is Sergeant Major (2000 - 5000 Reputation Level)blicci User rank is Sergeant Major (2000 - 5000 Reputation Level)blicci User rank is Sergeant Major (2000 - 5000 Reputation Level)blicci User rank is Sergeant Major (2000 - 5000 Reputation Level)blicci User rank is Sergeant Major (2000 - 5000 Reputation Level)blicci User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 3 Days 22 h 8 m 5 sec
Reputation Power: 52
It sounds to me like what you really want is group by clause.

Reply With Quote
Reply

Viewing: ASP Free ForumsDatabaseMicrosoft SQL Server > stored proc looping through returned result from select


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
Stay green...Green IT