Sunday, July 15, 2007

It's not uncommon for my apps to have a requirement where a user is given the ability to sort data in a grid by clicking on column headers. The usual problem I've encountered with this requirement is when I have to sort a numeric column that's represented as a string. The following table compares the numeric and string sort:
Numeric sortNumeric string sort
11
510
6150
1020
205
1506


So if I had a column that was stored numerically and had to represent that column with a unit of measurement, i.e. 150 GB, the sorting would be messed up.

A workaround I used recently was to include that column twice in my SELECT statement, one as numeric and the other as a CAST to string/char. Then I'd show the string column in my grid and hide the numeric one. But whenever I sort, I use the numeric one.

0 Comments:

Post a Comment

<< Home