left join #STORES S on S.store=a.Store and S.Quarter=a.Q ,count(case when 'q1' in (quarter) then 1 end) as cnt_q1 ,count(case when 'q2' in (quarter) then 1 end) as cnt_q2 ,count(case when 'q3' in ...