|
|
|||||||||
|
|||||||||
|
|||||||||
| |
||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
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 |
|
#2
|
||||
|
||||
|
It sounds to me like what you really want is group by clause.
|
![]() |
| Viewing: ASP Free Forums > Database > Microsoft SQL Server > stored proc looping through returned result from select |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|