Connecting Tech Pros Worldwide Forums | Help | Site Map

MS Access Skip the first character in a field and then sort

Member
 
Join Date: Oct 2007
Posts: 102
#1: Dec 19 '08
Hey everyone!

I'm working in Access 2003 and need help with the 'order by' in a query. I have an CrewCode that includes a letter as well as numbers, and I want to sort by the numbers. The CrewCodes are for instance:

D5159
D1801
D337
D5276

When I just sort by ascending, it's all out of order. How would I do this?

THANKS SO MUCH!!!

Member
 
Join Date: Oct 2007
Posts: 102
#2: Dec 19 '08

re: MS Access Skip the first character in a field and then sort


Hey yall,

I figured out a solution!
Expand|Select|Wrap|Line Numbers
  1. SELECT IIf(IsNull([CrewCode]),"",Format$(Right([CrewCode],Len([CrewCode])-1),"0000")) AS [Check]
  2. FROM tblCrews
  3. ORDER BY IIf(IsNull([CrewCode]),"",Format$(Right([CrewCode],Len([CrewCode])-1),"0000")) DESC;
ADezii's Avatar
Expert
 
Join Date: Apr 2006
Location: Philadelphia
Posts: 5,216
#3: Dec 20 '08

re: MS Access Skip the first character in a field and then sort


Quote:

Originally Posted by jmarcrum View Post

Hey yall,

I figured out a solution!

SELECT IIf(IsNull([CrewCode]),"",Format$(Right([CrewCode],Len([CrewCode])-1),"0000")) AS [Check]
FROM tblCrews
ORDER BY IIf(IsNull([CrewCode]),"",Format$(Right([CrewCode],Len([CrewCode])-1),"0000")) DESC;

A slightly different approach:
Expand|Select|Wrap|Line Numbers
  1. SELECT IIf(IsNull([CrewCode]),"",Format$(Mid$([CrewCode],2),"0000")) AS [Check]
  2. FROM tblCrews
  3. ORDER BY IIf(IsNull([CrewCode]),"",Format$(Mid$([CrewCode],2),"0000")) DESC;
NeoPa's Avatar
Administrator
 
Join Date: Oct 2006
Location: London - UK
Posts: 15,730
#4: Dec 22 '08

re: MS Access Skip the first character in a field and then sort


That's a neat solution :)

Please though, remember in future to use the [ CODE ] tags provided. As a full member now, I wouldn't expect to be needing to say this.
Reply

Tags
access, letters, numbers, order, sort