Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
Trent
Starting Member
39 Posts |
Posted - 2004-09-10 : 08:50:12
|
| I got as far as the code below:*******************************CREATE PROCEDURE usp_Groups@StudyNo char(16) ASdeclare @Fill table (GroupID varchar(5), TesterID char(7))declare @Ct table (GroupID varchar(5), TesterID char(7), Filled varchar(4))declare @Out table (GroupID varchar(5), TesterID char(7), Filled varchar(4))insert @FillSELECT DISTINCT tGroup.GroupID, tResultQue.TesterIDFROM tGroup INNER JOIN tResultQue ON tGroup.GroupID = tResultQue.GroupIDwhere (tResultQue.QueStatusID >= '20') and (tResultQue.QueStatusID <= '22') and tGroup.StudyNo = @StudyNoinsert @Ctselect distinct F.GroupID, F.TesterID, @@Rowcount as Filledfrom @Fill FGroup by F.GroupID, F.TesterIDinsert @Outselect distinct F.GroupID, F.TesterID, Ct.Filledfrom @Fill F left join @Ct Ct on (F.GroupID = Ct.GroupID)SELECT distinct tGroup.GroupID, tGroup.ScheduleStamp, tFacility.FacilitiesDescription, tGroup.NotToExceed, (tGroup.NotToExceed- Gonzo.Filled) as AvailableFROM tGroup INNER JOIN tFacility ON tGroup.FacilityID = tFacility.FacilityID left join @Out Gonzo on (tGroup.GroupID = Gonzo.GroupID) left join @Fill J on (tGroup.GroupID = J.GroupID) left join @Ct Cet on (tGroup.GroupID = Cet.GroupID)where tGroup.StudyNo = @StudyNoGO*************************************************That outputs this:GroupID|ScheduleStamp|FacilitiesDescription|NotToExceed|Available-----------------------------------------------------------------859 |2004-2-24 |Building A |15 |11860 |2004-2-24 |Building A |10 |6861 |2004-5-04 |Building A |10 |NULL****************************************************The @@Rowcount needs to be specific to the GroupID like below:GroupID|ScheduleStamp|FacilitiesDescription|NotToExceed|Available-----------------------------------------------------------------859 |2004-2-24 |Building A |15 |12860 |2004-2-24 |Building A |10 |9861 |2004-5-04 |Building A |10 |NULL*******************************************************The difference between the two is that there are three people who are associated with GroupID 859 and one with 860 and zero with 861. Right now it's subtracting them all from 859 and 860.Thank you for any help! |
|
|
Seventhnight
Master Smack Fu Yak Hacker
2878 Posts |
Posted - 2004-09-10 : 08:55:54
|
show some sample data (before any queries) and the desired output... it is much easier to work with that way My initial guess is don't join the filled spotsSelectgroupId,...Available = NotToExceed - (Select count(*) From @filled where groupId = A.groupId)From tGroup...Corey |
 |
|
|
Trent
Starting Member
39 Posts |
Posted - 2004-09-10 : 09:04:49
|
| Wow, that was quick, and it works-Thank you very much Corey! |
 |
|
|
|
|
|
|
|