Hi All,I am using this query to get the results i need from my SQL database. and it is working in SQL management studio but when i put it in a bespoke web application sql browser which i have to do it says there is "Incorrect syntax near the keyword 'with'" Is there another way of writing this query to simplify it?Thanks for looking!with cteDelegates ( company, postalcode, last_hs, next_hs, risk_level, sct1, sct2, training_provider, rown) as (Select wce_course_delegate_link.edrs_no, wce_contact.company, postalcode, wce_contact.last_hs, wce_contact.next_hs, wce_contact.risk_level, wce_course_delegate_link.sct1, wce_course_delegate_link.sct2, wce_course_delegate_link.training_provider, ROW_NUMBER() OVER (PARTITION BY wce_course_delegate_link.edrs_no ORDER BY wce_course_delegate_link.edrs_no, wce_course_delegate_link.sct1) from wce_course_delegate_link left join wce_contact on wce_course_delegate_link.edrs_no = wce_contact.edrs where wce_course_delegate_link.end_date is null and wce_contact.record_type = 'company') Select edrs_no, company, postalcode, last_hs, next_hs, risk_level, sct1, sct2, training_provider from cteDelegates where rown = 1 order by edrs_no