Help with Activities Database Query

Discussion created by JohnO'Mullane on Apr 18, 2016
Latest reply on Jul 13, 2016 by JohnO'Mullane
I'm trying to create a SQL variable that will give me a list of all active Schedules/Events/C_PERIODS in my activities windows. 
I have put something together myself but it is taking longer that I would like to complete (~15 secs). 

select ah_name from ah 
where ah_otype in ('!EVNT','JSCH','C_PERIOD') 
and ah_status in (0,1815) 
and ah_client = &$CLIENT# 
and ah_deleteflag = 0 
order by 1 

I can understand why it is taking some time as we do have ~8 Million rows in AH table so looking at my archiving/purging process may be the only answer.
I opened a ticket with support who have suggested a post in the community instead.

Anyone out there able to help?