Hey,Im having some problems with this (after having a look at the article mentioned above)My code is as such: SELECT DISTINCT r.userID, r.firstname, r.surname, r.jobTitle, l.Suppliername1, r.dateAdded, r.deleted, getUsername(r.Addedby) AS AddedBy ,getUsername(r.deletedby) AS DeletedBy FROM TLRegistrations r INNER JOIN Users u ON r.userID = u.UserID INNER JOIN l ON l.recordID = u.locationID INNER JOIN Companies c ON c.companyID = l.CompanyIDWHERE r.Deleted IS NULL ORDER BY CASE WHEN @orderBy = 'surname, r.firstname, l.suppliername1' THEN r.surname WHEN @orderBy = 'l.suppliername1, surname, r.firstname' THEN l.suppliername1 END
I'm getting the error:'ORDER BY items must appear in the select list if SELECT DISTINCT is specified.'and I also get an error if trying to order by more than one columnie: WHEN @orderBy = 'surname, r.firstname, l.suppliername1' THEN r.surname, r.firstnameany ideas?Any help much appreciated, taPete