Hi all please look at my table below
Name
----------
Banaskantha - 66-DV
Banaskantha - 66-MM
Banaskantha-Dv
Banaskantha-MM
Bharuch - 77-RP
Bharuch-RP
hg-SR
but I want this table in below order
Name
-------------
Banaskantha-Dv
Banaskantha-MM
Banaskantha - 66-DV
Banaskantha - 66-MM
Bharuch-RP
Bharuch - 77-RP
hg-SR
How can I do that ?
Try the following sql statement:
The query adds a field for sorting purposes. The value of that field depends if the name field has numeric value in it. If yes, it converts it to perfix (i.e. ‘Banaskantha’) + ‘z’ (so it will be below any instance of the prefix without the suffix), suffix (i.e. ‘DV’) + the numeric value. If it has no numeric value then it keeps the original value.
I made several assumptions:
If one of the assumptions is not correct, rewrite the SQL statement accordingly.
Let me say that the problem starts because there is no consistency in the field value. In such case I would suggest to create a field in the table for sorting purposes and populate it based on insert and update triggers.