Login ProductsSalesSupportDownloadsAbout |
Home » Technical Support » ElevateDB Technical Support » Support Forums » ElevateDB SQL » View Thread |
Messages 1 to 3 of 3 total |
Explicit order clause? |
Mon, Feb 1 2016 3:06 PM | Permanent Link |
Gregory T Swain Zucchetti North America LLC | Is there any way for an explicit sort order? Ex:
Select ID, Name, Val from TblMyTable order by Name ("john", "andrew", "bill"); | ID | NAME | VAL -------------------------------- 3 | John | 'abc' 1 | Andrew | '321' 2 | Bill | NULL |
Mon, Feb 1 2016 4:43 PM | Permanent Link |
Jeff Cook Aspect Systems Ltd | On 2/02/2016 9:06 a.m., Gregory T Swain wrote:
> Is there any way for an explicit sort order? Ex: > > Select ID, Name, Val from TblMyTable order by Name ("john", "andrew", "bill"); > > | ID | NAME | VAL > -------------------------------- > 3 | John | 'abc' > 1 | Andrew | '321' > 2 | Bill | NULL > How about:- SELECT ID, Name, Val, IF(Name = 'john' THEN 1 ELSE IF(Name = 'andrew' THEN 2 ELSE IF(Name = 'bill ' THEN 3 ELSE 0))) AS Seq -- probably a CASE statement instead of the IF's FROM TblMyTable ORDER BY seq, ID HTH Jeff |
Tue, Feb 2 2016 5:29 AM | Permanent Link |
Roy Lambert NLH Associates Team Elevate | Gregory
If you only have a few names/records to bother about I'd use Jeff's approach. If there are more I'd add in a computed column and come up with a mechanism to generate a value based on the name - like soundex but customised to your needs and then sort of the computed column. Roy Lambert |
This web page was last updated on Monday, April 29, 2024 at 05:23 AM | Privacy PolicySite Map © 2024 Elevate Software, Inc. All Rights Reserved Questions or comments ? E-mail us at info@elevatesoft.com |