Quote:
quote:
I would suggest an identity column.
|
And just how would ordering on an identity column solve the OP's problem? What relationship would the value of the identity column on a given row have to the column to be sorted so that the the rows would be "properly" ordered? What if a new row were inserted with a sort column value in between existing rows. The identity value would be "far away" from the existing rows, so how would that help?
To the OP:
The problem is that the column is a composite column - a value comprised of two other values. This is a violation of first normal form and this design is likely to be doomed to ongoing difficulties. The fact that you want to sort in a particular way on two distinct portions of the column tells me you have attached meaning to each distinct piece. Why did you combine these meanings into a single value?
Suppose instead that the original column was split into two columns: the first containing the numeric portion of the original column, and the second containing the string portion. Then, if I understand your desired ordering, it would be by the string portion and then the numeric portion within each string value.
Separate them out; things will be much easier.
If you really can't (why?), you could (if SQL Server 2000), write two user defined functions: one to parse off and return the leading numeric portion, and another the string portion. You would then order by the string function, then the numeric function value within the string value.
In SQL Server 2000, you can use the SUBSTRING and ISNUMERIC functions to extract off the leading numeric characters of the input column then CAST them to a numeric value.
Using functions this way would be very slow. It would be orders of magnitude faster if the column values were split correctly in the first place...
Good luck.
Jeff Mason
Custom Apps, Inc.
www.custom-apps.com