Hi
if you want user input to be dynamic(if you don't know how many Activitytype or Activityid going to come from user selection )
you can form a search table to compare like i have used @searchtab in below script
i believe you are looking of Activitytype as one group(swimming & Football, etc), you are looking for the employee have multiple activity type as user may select
then my below example may help , i don't understandwhy you want to insert activityID's and types after searching the employee
<<that I can dynamically insert activityID's and types as needed on the fly before sending of to Sql Server.>>
GO
Create table #EmployeeActivities
(
employeeid int,
ActivityType int,
ActivitiyId int
)
GO
insert into #EmployeeActivities
select 1,1,1571 union all -- let's assume Swimming
select 1,7,1625 union all -- let's assume Programming
select 2,1,1572 union all --let's assume Football
select 2,7,1625 -- let's assume Programming
Declare @searchtab table(ActivityType int,ActivitiyId int)
insert into @searchtab
select 1,1571 union all -- let's assume Swimming
select 7,1625 union all -- let's assume Programming
select 1,1572
SELECT EmployeeId FROM #EmployeeActivities a inner join @searchtab b on
a.ActivitiyId=b.ActivitiyId and a.ActivityType=b.ActivityType
group by EmployeeId
having COUNT(DISTINCT a.ActivityType) = (select COUNT(DISTINCT ActivityType) from @searchtab)
Thanks
Saravana Kumar C
No comments:
Post a Comment