Hi folks,
i have a list of alphanumeric tokens, say '1a', '1b', '02', '03', '10', '11',
etc...
Now, what's the best way to do an order by on this list of tokens?
I am getting '1a', '1b', '10', '11', '02', '03',
but i need it to be
'1a', '1b', '02', '03', '10', '11'
UPDATE
ok, i am doing this after the suggestion but it's not working.
declare @tokens table(token varchar(20));
insert into @tokens
select '1a'
select '1b'
select '02'
select '10'
select * from @tokens
order by case
when ISNUMERIC(token) = 1 then right('0000000000'+token+'0',10)
else right('0000000000'+token,10)
end
I am getting the response as '1b', '02', '10', '1a'
UPDATE2
It works after making the following change.
declare @tokens table(token varchar(20));
insert into @tokens
select '1a'
insert into @tokens
select '1b'
insert into @tokens
select '02'
insert into @tokens
select '10'
select token from @tokens
order by case
when ISNUMERIC(token) = 1 then right('0000000000'+token+'0',10)
else right('0000000000'+token,10)
end
Thanks to all of you for your nice ideas.