hi ,
I'm trying to optimize a stored procedure which has a lengthy expression and a subquery . Can any one help me out to fine tune below expresion and a join condition.
extension_out = count(distinct case when (coalesce(rtrim(ltrim(f.origlogin)),'')<>'' and f.conference <> 1 and f.transferred <> 1 and d.destination_dim_id! = 0 and coalesce(rtrim(ltrim(f.origlogin)),'')<>coalesce(rtrim(ltrim(f.anslogin)),'')) then f.callid else null end), warm_transfer = count(distinct case when coalesce(rtrim(ltrim(f.anslogin)),'')<>'' and f.conference = 1 then f.callid else null end), cold_transfer = count(distinct case when coalesce(rtrim(ltrim(f.anslogin)),'')<>'' and f.transferred = 1 then f.callid else null end), ------------------------ ----------------------- --Sub Query ---------------------- --------------------- join etl_dm.dbo.tblcchassociatehierarchybridge b (nolock) on f.date_id = b.date_id and mp.date_id = b.date_id and h.associate_id = b.associate_id where not exists( select 1 from etl_dm.dbo.tblcct_work_excludemu ex (nolock) where ex.metric_table_id = @metric_table_id and ex.mu_id = h.iex_mu_id and ex.start_effective_date <= @date and (ex.end_effective_date is null or ex.end_effective_date >= @date))
Thansk for help !