Re: Changing Ordering
- From: Hugo Kornelis <hugo@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Tue, 07 Feb 2006 00:10:28 +0100
On Mon, 6 Feb 2006 02:11:30 -0800, Sian wrote:
Sorry I don't think I explained my problem properly. I can't just use desc
as this isn't what I need.
For example, I have the following parts on the shelf, in this (logical) order:
Table 1
FDB2
FDB12
FDB125
FDB1000
FDB2100
However, if I run a report that includes these part numbers on T21, the
report sorts them as follows:
Table 2
FDB1000
FDB12
FDB125
FDB2
FDB2100
I can see the sorting logic here (ie part no. is not an integer and
therefore it is read and sorted as text - from left to right) but I?m afraid
this sort order (Table 2) is no good.
We need a system option to manage/redefine sort orders for alpha-numeric
part numbers on all reports that contain part number lists.
Hi Sian,
I was afraid of this....
The problem is caused by a flawed design. Apparently, these part numbers
are not a single code, but a concatenation of two attributes. And at
least one of those attributes has more meaning than just identifying a
part.
Since "FDB" and "1000" are two distinct attributes, they should have
been stored in two distinct columns. You can always concatenate them in
the front-end, in a view, or -if you really must- in a computed column
in the base table.
Until you get your design fixed, you can try using this kludge as a
temporary workaround:
ORDER BY LEFT(BadColumn, 3),
CAST(SUBSTRING(BadColumn, 4, LEN(BadColumn) - 3) AS integer)
However, this *will* break if you have any data in the table where the
part number doesn't follow the same layout. And it will perform very
bad, because the optimizer can't leverage an index on the BadColumn to
facilitate the sorting operation.
--
Hugo Kornelis, SQL Server MVP
.
- References:
- Re: Changing Ordering
- From: Hugo Kornelis
- Re: Changing Ordering
- From: Sian
- Re: Changing Ordering
- Prev by Date: Re: Changing Ordering
- Next by Date: Re: Date Selection
- Previous by thread: Re: Changing Ordering
- Next by thread: Re: Changing Ordering
- Index(es):
Relevant Pages
|
|