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.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 T-sql problem

Author  Topic 

sbolton1855
Starting Member

2 Posts

Posted - 2010-03-22 : 10:59:29
How do I alter the below code to pull specific activities that have been completed... This query is implimented in SSRS where the facility number (code) is selected and then the activity is selected from radio boxes, and then the results will be how many Registered / who have Completed the activity..... The current query pulls every registered and completed b/c there is no WHERE, but when I insert WHERE's i get no results!

The current query returns the title of the activity, registered of 589716 and completed of 25113 . This returns ALL registered and completed. But the code i am trying to write needs to be able to understand what activity and facility i have selected and pull data only from those criteria. So the results will be specific to the people that have completed that activity within the facility.

thx in advance this has been a pain

DECLARE 
@registered int,
@completed int,
@title nvarchar(50),

@ActivityId int,
@FacilityCode varchar

SET @FacilityCode = '102'
SET @ActivityId= '10'

SELECT @registered = COUNT(*)
FROM XREFEmployeesInvitations EE
JOIN Employees E ON EE.EmployeeId = E.ID
JOIN Activities EV ON EE.ActivityId = Ev.Id
JOIN Locations L ON E.LocationId = L.Id
Join Facilities F ON F.Id = L.FacilityId

/*WHERE EV.Id = @activityId
AND F.Code = @FacilityNumber*/??????

SELECT @completed = COUNT(*)
FROM XREFEmployeesInvitations EE
JOIN Employees E ON EE.employeeId = E.ID
JOIN Activities EV ON EE.ActivityId = Ev.Id
JOIN Locations L ON E.LocationId = L.Id
Join Facilities F ON F.Id = L.FacilityId



AND IsCompleted = 1

SELECT @title = Title
FROM Activities
WHERE ID = @ActivityId

SELECT @title As Title, @registered AS Registered, @completed As Completed

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-03-22 : 11:55:17
didnt understand why it didnt work when you put where conditions..may be you could explain with some data to make it more clear

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

sbolton1855
Starting Member

2 Posts

Posted - 2010-03-22 : 12:57:54
Ahh my fields were wrong thtas why it didnt work..... here is the right code that works...(i put this where on the top 2 where statements and it worked finally!!

WHERE E.Id=@ActivityId
and F.id = @FacilityNumber
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-03-22 : 12:59:16
ok..
Glad tht you spotted it out

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -