Maybe it is taking ling time because you are mixing INTEGERS and VARCHAR for PhaseSortSELECT Phase, Stat, Subject, CASE WHEN Phase = 'Initial/Data Collection' THEN '1' WHEN Phase = 'Screening' THEN '2' WHEN Phase = 'Assessment and Selection' THEN '3' WHEN Phase = 'Placement' THEN '4' END AS PhaseSortFROM ( SELECT Subject, Stat, CASE WHEN Stat = 'Application Received' THEN 'Initial/Data Collection' WHEN Stat IN ('Shortlisted', 'For Screening') THEN 'Screening' WHEN Stat IN ('For Assessment', 'Passed Initial Evaluation', 'Passed Profiles Exam', 'Passed Technical Exam') THEN 'Assessment and Selection' WHEN Stat = 'For Placement' THEN 'Placement' END AS Phase FROM ( SELECT Subject, CASE WHEN Subject IN ('Process Application', 'Application Received') THEN 'Application Received' WHEN Subject = 'Screen Application' THEN 'For Screening' WHEN Subject = 'Phone interview' THEN 'Shortlisted' WHEN Subject = 'Initial Interview' THEN 'For Assessment' WHEN Subject = 'Profiles assessment'THEN 'Passed Initial Evaluation' WHEN Subject = 'Technical Exam and Interview' THEN 'Passed Profiles exam' WHEN Subject = 'background and reference check' THEN 'Passed Technical Exam' WHEN Subject IN ('Job Offer', 'Contract Signing') THEN 'For Placement' END AS Stat FROM dbo.FilteredTask WHERE Subject = 'application received' OR Subject = 'process application' OR Subject = 'screen application' OR Subject = 'initial interview' OR Subject = 'profiles assessment' OR Subject = 'technical exam and interview' OR Subject = 'background and reference check' OR Subject = 'phone interview' OR Subject = 'shortlisted' OR Subject = 'For Placement' OR Subject = 'job offer' OR Subject = 'contract signing' ) AS Phases ) AS StatsORDER BY PhaseSort
Peter LarssonHelsingborg, Sweden