I'm stumped by a sorting order my customer needs on a field containing a multipart numeric code. Code consists of a country code, a letter, a two-digit year code and then an increment, for instance
31S03008
would be a record in the Netherlands (country code 31), and number 008 there in the year 2003.
What the customer wants is to have the records sorted reverse chronologically on year and then on increment. Until recently, our oldest records were from 2001, meaning I could just do
ORDER BY RIGHT(Column1 , 5)
and I'd get results like:
(...)04003
(...)04002
(...)04001
(...)03672
(...)03671
(etc.)
Unfortunately we just imported legacy data going back to 1998, which means that if I do this, records from '98 and '99 appear above those from 2004: after all, '99' is recognized as a higher number than '04'.
Can anybody think of a way I could sort it such that 04, 03, 02, 01, 00 come first and only after that 99, 98? Changing the way those codes are formatted is probably not an option.
Thanks in advance!
"Much that I bound, I could not free. Much that I freed returned to me."
(Lee Wilson Dodd)
31S03008
would be a record in the Netherlands (country code 31), and number 008 there in the year 2003.
What the customer wants is to have the records sorted reverse chronologically on year and then on increment. Until recently, our oldest records were from 2001, meaning I could just do
ORDER BY RIGHT(Column1 , 5)
and I'd get results like:
(...)04003
(...)04002
(...)04001
(...)03672
(...)03671
(etc.)
Unfortunately we just imported legacy data going back to 1998, which means that if I do this, records from '98 and '99 appear above those from 2004: after all, '99' is recognized as a higher number than '04'.
Can anybody think of a way I could sort it such that 04, 03, 02, 01, 00 come first and only after that 99, 98? Changing the way those codes are formatted is probably not an option.
Thanks in advance!
"Much that I bound, I could not free. Much that I freed returned to me."
(Lee Wilson Dodd)