I have a table containing 2 types of text inside a column. The first type is an email address string (ex 222@dsad.com) and the second is a persons name (John Doe)
I am using this query to get the data sorted so that first the rows that don’t have the @ char are shown and then the ones that do have it:
SELECT *
FROM Name
ORDER BY CASE
WHEN displayName LIKE '%@%' THEN 1
ELSE 2
END
So what I am unable to do is get the cases to be sorted ascending so that I have the names sorted by letter ascending following the emails sorted by letter ascending.
Use:
The
ORDER BYclause supports more than one column, but the priority is read left to right. So thedisplaynamevalues with an “@” in them are at the top, and then ordered by thedisplaynamevalue in that each grouping (based on the CASE statement).You need to look at using the COLLATE operator for case insensitive comparison.