You basically need to extract the numeric portion out of the data and order it that way.
You have two options:
1. Have a humungous CASE statement which extracts the numeric portion on the fly and orders by it.. you need to have an option for every single format that that the data is entered.
2. Create a UDF that extracts the numeric part. This will simplify the code but slwo down your report.
3. Do some data cleansing on your table and load it into a new clean table, and select from the clean table.
I recommend option 3 but you might have some constraints on what you can do.
To give you some ideas about option 1:
SELECT *
FROM YourTable
ORDER BY
CASE WHEN ISNUMERIC(ApartmentNumber)
ApartmentNumber
What this does is has two ordering criteria.
It first orders by the apartment number if it is totally numeric.
If the apartment number is not totally numeric it orders by the apartment number alphabetically.
This does not do what you requested but it gives you an idea of the complexity required if you want to try and do this on the fly.
Main Topics
Browse All Topics





by: QPRPosted on 2006-11-06 at 17:36:41ID: 17886357
Not to my knowledge. Your column is a varchar and will therefore order 1-0,a-z