August 13, 2004 at 11:41 am
Is it possible to sort a field which is a string and i m storing data
ie.1,2,3,10,4,11 . I want result of a query to be like
1
2
3
4
10
11
it is possible to write a query for this as data type is char or varchar so if i use order by clause i will get the result in this order 1,10,11,2,3,4
August 13, 2004 at 11:55 am
Try
ORDER BY
CAST(column AS varchar(10))
August 13, 2004 at 12:38 pm
Probably wanted
ORDER BY
CAST(Column AS int)
or
ORDER BY
CONVERT(int,Column)
If there is nonnumeric data in the column
the ISNUMERIC function might be handy.
/rockmoose
You must unlearn what You have learnt
August 15, 2004 at 12:59 am
Thanks u all for solving my problem
August 16, 2004 at 6:23 am
simplest way is
ORDER BY RIGHT('0000000000'+COLUMN,10)
August 16, 2004 at 8:52 am
How about,
Order by len(COLUMN),Column
Viewing 6 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply