Re: SQL Text and Number sort
- From: "Richard Mueller" <rlmueller-NOSPAM@xxxxxxxxxxxxxxxxxxxx>
- Date: Tue, 4 Apr 2006 12:23:02 -0500
Hi,
I think you can convert the SQL to VB. You would have to loop through the
data (a recordset) and create the new field to sort on. Or better yet,
create the new field as you read the data from it's source into a recordset.
In rough outline:
If IsNumeric(Field1) Then
NewField = Right("00000" & Trim(Field1), 5)
Else
NewField = Field1
End If
--
Richard
Microsoft MVP Scripting and ADSI
Hilltop Lab - http://www.rlmueller.net
"Patch61" <Patch61@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:FE00AECA-EF77-4253-A7C0-C16DA5E3E036@xxxxxxxxxxxxxxxx
Thanks, but I need to do this in MS Jet/VB6.
"Stephen Howe" wrote:
I have a field I am sorting on that is a text field which includesnumbers.
Is there any way to sort this field so that, for example, 2356 comesbefore
12685 while maintaining alphabetical order for the true text entries?
I can do it using SQL Server using a hack
SELECT field1
FROM table1
ORDER BY
CASE ISNUMERIC(field1)
WHEN 0 THEN field1
WHEN 1 THEN RIGHT('0000' + LTRIM(RTRIM(field1)), 4)
END
field1 is a 4 character field.
I am distinguishing numeric from non-numeric and adding leading 0's to
the
numeric so that is sorts properly.
Stephen Howe
.
- References:
- Re: SQL Text and Number sort
- From: Stephen Howe
- Re: SQL Text and Number sort
- Prev by Date: Re: SQL Text and Number sort
- Next by Date: Re: Not enough storage is available to complete this operation
- Previous by thread: Re: SQL Text and Number sort
- Next by thread: Re: Not enough storage is available to complete this operation
- Index(es):
Relevant Pages
|
|