Apr 13, 2006 #1 mkingrey Programmer Joined Apr 12, 2006 Messages 5 Location US I have a recordset that I would like to sort letters to appear first then numbers to appear last. Is it possible to sort like the following? A B C R 2 3 4 7
I have a recordset that I would like to sort letters to appear first then numbers to appear last. Is it possible to sort like the following? A B C R 2 3 4 7
Apr 13, 2006 #2 Juice05 Programmer Joined Dec 4, 2001 Messages 247 Location US How about this? It works in MSSQL. Code: Select Field, Case IsNumeric(Field) When 1 Then '1' + Field Else '0' + Field End D From Table Order By D Upvote 0 Downvote
How about this? It works in MSSQL. Code: Select Field, Case IsNumeric(Field) When 1 Then '1' + Field Else '0' + Field End D From Table Order By D
Apr 13, 2006 #3 JarlH Programmer Joined Jul 26, 2002 Messages 365 Location SE And here's an ANSI/ISO compliant solution: Code: SELECT ... FROM ... WHERE ... ORDER BY CASE WHEN SUBSTRING(field FROM 1 FOR 1) BETWEEN '0' AND '9' THEN 1 ELSE 0 END, FIELD; I.e. if first character is 0 - 9, place after all other rows. (Or you can use a collation which sorts digits after letters, if available...) Upvote 0 Downvote
And here's an ANSI/ISO compliant solution: Code: SELECT ... FROM ... WHERE ... ORDER BY CASE WHEN SUBSTRING(field FROM 1 FOR 1) BETWEEN '0' AND '9' THEN 1 ELSE 0 END, FIELD; I.e. if first character is 0 - 9, place after all other rows. (Or you can use a collation which sorts digits after letters, if available...)