Well, right now I'm doing the sort in SQL. That's the problem. Since its a
character-type field, I can't get MySQL to sort properly.

I guess I could use DBI::fetchall_arrayref to fetch all the data at once,
then sort the array of records the way I need them. However, what I'm hoping
for is some SQL expert to tell me this would be a silly approach!

-- John

> -----Original Message-----
> From: Wagner, David --- Senior Programmer Analyst --- WGO
> [mailto:[EMAIL PROTECTED]]
> Sent: Wednesday, September 25, 2002 4:48 PM
> To: 'John Almberg'; Beginners
> Subject: RE: How to sort a character-type field, numerically
>
>
>
>       You should be able to sort it numerically if I understand where the
> data is coming from.  Could you provide a snippet of the code and
> from there
> it should not be that hard to provide code to sort numerically.
>
> Wags ;)
>
> -----Original Message-----
> From: John Almberg [mailto:[EMAIL PROTECTED]]
> Sent: Wednesday, September 25, 2002 13:18
> To: Beginners
> Subject: How to sort a character-type field, numerically
>
>
> I'm trying to sort a SQL table that contains a character-type field that
> contains mostly numbers. This field always contains either a number or a
> number followed by a character. Like '57' or '57a'.
>
> I'd like to sort the table *numerically* on this field, not
> *alphabetically*
> on this field. That is, I'd like the table to be sorted like:
>
> 1 ...
> 2a ...
> 3 ...
> 4d ...
>
> NOT like:
>
> 1 ...
> 11 ...
> 111a ...
> 2a ...
> 22 ...
>
> See what I mean? This is a common problem, I think, when you sort an
> character type field that contains numbers. The sort comes out all wrong.
>
> It would be great if I could get rid of the characters, then I could make
> the field a pure integer and the sort would work great, but that's not
> possible (or easily possible.)
>
> A pseudo-code solution would be SELECT * FROM table ORDER BY
> INT(char-field), but unfortunately even MySql doesn't have such an INT()
> cast funtion.
>
> I'm asking this perl group, because I suspect that my only solution is to
> sort the result set in perl. Am I right about this???
>
> Thanks.
>
> -- John
>
>
>
> --
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>
> **********************************************************
> This message contains information that is confidential
> and proprietary to FedEx Freight or its affiliates.
> It is intended only for the recipient named and for
> the express purpose(s) described therein.
> Any other use is prohibited.
> ****************************************************************
>


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to