Groups | Blog | Home
all groups > dotnet ado.net > august 2006 >

dotnet ado.net : Sorting



Adrian
8/31/2006 12:00:00 AM
When I sort a number I get a lexicographical sort
1
11
112
1
12
How can I code a sort that will produce
a proper numerical order?

Adrian.

mcw8 NO[at]SPAM aber.ac.uk
8/31/2006 5:40:23 AM
[quoted text, click to view]

Youre sorting text, not numbers. It matters little to the computer that
the text is composed entirely of numeric characters - it's text, not a
number


[quoted text, click to view]

Use numbers, not text
Miha Markic [MVP C#]
8/31/2006 1:00:24 PM
Hi Adrian,

Why don't you set column's DataType to a numeric one (I guess you have it
set to string now).

--
Miha Markic [MVP C#, INETA Country Leader for Slovenia]
RightHand .NET consulting & development www.rthand.com
Blog: http://cs.rthand.com/blogs/blog_with_righthand/

[quoted text, click to view]

Adrian
8/31/2006 1:13:56 PM
[quoted text, click to view]

Miha,

Yes, but more generally I was looking for an expression like
VALUE([column name]) in a SQL command line.

Adrian.

Miha Markic [MVP C#]
8/31/2006 1:58:25 PM
Hi,

So you want to do sorting on database. What database?

--
Miha Markic [MVP C#, INETA Country Leader for Slovenia]
RightHand .NET consulting & development www.rthand.com
Blog: http://cs.rthand.com/blogs/blog_with_righthand/

[quoted text, click to view]

Adrian
8/31/2006 2:10:07 PM
[quoted text, click to view]

SqlServer 2005 Express

Miha Markic [MVP C#]
8/31/2006 2:46:08 PM
You might use cast or convert function and sort on the result, something
like ... order by case(comecolumn as int)

--
Miha Markic [MVP C#, INETA Country Leader for Slovenia]
RightHand .NET consulting & development www.rthand.com
Blog: http://cs.rthand.com/blogs/blog_with_righthand/

[quoted text, click to view]

Adrian
8/31/2006 5:43:16 PM
[quoted text, click to view]

Great. Thank you.

Adrian

Adrian
8/31/2006 5:43:56 PM
[quoted text, click to view]

Yes, I have changed the code.
Thanks,

Adrian.

AddThis Social Bookmark Button