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 |
sqlnewbie2015
Starting Member
1 Post |
Posted - 2015-01-05 : 14:58:22
|
Hi Everyone- I'd like to limit my query results to only items that match any part of a dynamic csv string table but am having some trouble (postgres SQL). Details: I need to calculate how many hours our staff spends seeing clients. Each staff has different appointments that can count toward this. The specified appointments for each staff are listed as comma separated values. My existing query calculates the appointment hours for each staff in a given time period. However, I need help limiting my query to only include specified activities for each staff. My current where clause uses IN to compare the appointment (i.e. activity) listed in the staff's schedule with what is listed an an approved appointment type (i.e. performance target activity). The query runs but it seems to only count one of the activities listed in the csv rather then count all the activities that match with the csv.Any help would be amazing!select (sum (kept)/60) from (select distinct rpt_scheduled_activities.staff_id as sid,rpt_scheduled_activities.service_date, rpt_scheduled_activities.client_id,from rpt_scheduled_activities inner join rpt_staff_performance_target on rpt_scheduled_activities.staff_id = rpt_staff_performance_target.staff_id where (rpt_scheduled_activities.status = 'Kept' and rpt_scheduled_activities.service_date between '01-nov-2014' and '30-nov-2014' and rpt_scheduled_activities.activity_name in (select regexp_split_to_table(rpt_staff_performance_target.activity,',') from rpt_staff_performance_target)) and rpt_scheduled_activities.staff_id = '55738') as p |
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2015-01-06 : 01:52:06
|
SQLTeam is for SQL Server. Please post this on postgres forumMadhivananFailing to plan is Planning to fail |
|
|
|
|
|