473,498 Members | 1,379 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

ORDER BY - "numerical string" problem

An ASP page outputs data from the query
"Select ThisAndThat from comments WHERE pageURL='" & pageURL & "' ORDER BY
threadID, datesent"
(Access mdb)
threadID is a string (OK, I know!), which means that 103 displays before 99.
Is there a way to write the SQL query to order them numerically? This would
be much easier for me than changing the data type and hunting down every
page that INSERTS or UPDATES the db.
Thanks, Giles
Jan 5 '06 #1
7 6314
You should correct the data instead of applying a band-aid. But, if you
choose not to:

ORDER BY CInt(threadID)...

BUT NEXT TIME, STORE NUMERIC VALUES AS NUMERIC DATA!

Ray at work

"Giles" <gi***@nospam.com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
An ASP page outputs data from the query
"Select ThisAndThat from comments WHERE pageURL='" & pageURL & "' ORDER BY
threadID, datesent"
(Access mdb)
threadID is a string (OK, I know!), which means that 103 displays before
99. Is there a way to write the SQL query to order them numerically? This
would be much easier for me than changing the data type and hunting down
every page that INSERTS or UPDATES the db.
Thanks, Giles

Jan 5 '06 #2
Thanks very much Ray. I'll go and put on the spiky belt now..!.

"Ray Costanzo [MVP]"
You should correct the data instead of applying a band-aid. But, if you
choose not to:

ORDER BY CInt(threadID)...

BUT NEXT TIME, STORE NUMERIC VALUES AS NUMERIC DATA!

Ray at work

"Giles" <gi***@nospam.com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
An ASP page outputs data from the query
"Select ThisAndThat from comments WHERE pageURL='" & pageURL & "' ORDER
BY threadID, datesent"
(Access mdb)
threadID is a string (OK, I know!), which means that 103 displays before
99. Is there a way to write the SQL query to order them numerically? This
would be much easier for me than changing the data type and hunting down
every page that INSERTS or UPDATES the db.
Thanks, Giles


Jan 5 '06 #3
I have a simular problem with a extra twist
I was using invoice numbers in ORDER BY converting the invoice number to
Integer

but them someone in accounts for some silly reason started overwriting the
invoice numbers with text

I used the row id instead as this is for the most part the same order, but
no always. some times invoice numbers are entered out of order, so the fix
is not perfect.

I assume I can use some sort of SQL statement like
CASE isnumeric(invoiceNumber )



"Ray Costanzo [MVP]" <my first name at lane 34 dot commercial> wrote in
message news:eI*************@TK2MSFTNGP14.phx.gbl...
You should correct the data instead of applying a band-aid. But, if you
choose not to:

ORDER BY CInt(threadID)...

BUT NEXT TIME, STORE NUMERIC VALUES AS NUMERIC DATA!

Ray at work

"Giles" <gi***@nospam.com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
An ASP page outputs data from the query
"Select ThisAndThat from comments WHERE pageURL='" & pageURL & "' ORDER
BY threadID, datesent"
(Access mdb)
threadID is a string (OK, I know!), which means that 103 displays before
99. Is there a way to write the SQL query to order them numerically? This
would be much easier for me than changing the data type and hunting down
every page that INSERTS or UPDATES the db.
Thanks, Giles


Jan 5 '06 #4
Slim wrote:
I have a simular problem with a extra twist
I was using invoice numbers in ORDER BY converting the invoice
number to Integer

but them someone in accounts for some silly reason started
overwriting the invoice numbers with text

I used the row id instead as this is for the most part the same
order, but no always. some times invoice numbers are entered out of
order, so the fix is not perfect.
Do you want character entries to appear before or after numeric entries?

I assume I can use some sort of SQL statement like
CASE isnumeric(invoiceNumber )


The original problem involved Access. I assume you are talking about SQL
Server? If so, then yes, CASE will be your solution, but I would avoid
ISNUMERIC (http://www.aspfaq.com/show.asp?id=2390). Assuming you want the
character entries to appear after the numeric entries:

ORDER BY
CASE WHEN
PATINDEX('%[^0-9]%',invoiceNumber)>0 THEN 999999999
ELSE CAST(invoiceNumber AS int) END,
invoiceNumber

Bob Barrows
--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.
Jan 5 '06 #5

"Bob Barrows [MVP]" <re******@NOyahoo.SPAMcom> wrote in message
news:ev**************@TK2MSFTNGP09.phx.gbl...
Slim wrote:
I have a simular problem with a extra twist
I was using invoice numbers in ORDER BY converting the invoice
number to Integer

but them someone in accounts for some silly reason started
overwriting the invoice numbers with text

I used the row id instead as this is for the most part the same
order, but no always. some times invoice numbers are entered out of
order, so the fix is not perfect.
Do you want character entries to appear before or after numeric entries?

I assume I can use some sort of SQL statement like
CASE isnumeric(invoiceNumber )


The original problem involved Access. I assume you are talking about SQL
Server? If so, then yes, CASE will be your solution, but I would avoid
ISNUMERIC (http://www.aspfaq.com/show.asp?id=2390). Assuming you want the
character entries to appear after the numeric entries:

actually before would be better as we are using looking at the last few

thanks for this


ORDER BY
CASE WHEN
PATINDEX('%[^0-9]%',invoiceNumber)>0 THEN 999999999
ELSE CAST(invoiceNumber AS int) END,
invoiceNumber

Bob Barrows
would this give them to me before?

ORDER BY
CASE WHEN
CAST(invoiceNumber AS int)
ELSE PATINDEX('%[^0-9]%',invoiceNumber)>0 THEN 999999999 END,
invoiceNumber
thanks
--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.

Jan 6 '06 #6
Slim wrote:

ORDER BY
CASE WHEN
PATINDEX('%[^0-9]%',invoiceNumber)>0 THEN 999999999
ELSE CAST(invoiceNumber AS int) END,
invoiceNumber

Bob Barrows


would this give them to me before?

ORDER BY
CASE WHEN
CAST(invoiceNumber AS int)
ELSE PATINDEX('%[^0-9]%',invoiceNumber)>0 THEN 999999999 END,
invoiceNumber


No, this will raise an error, which you would have discovered if you had
taken the 30 seconds to actually try it ... ;-)

This is how it would be done:
ORDER BY
CASE WHEN
PATINDEX('%[^0-9]%',invoiceNumber)=0 THEN 'zzzzzzzzzz'
ELSE invoiceNumber END,
CASE WHEN
PATINDEX('%[^0-9]%',invoiceNumber)>0 THEN -1
ELSE CAST(invoiceNumber AS int) END

Bob Barrows
--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"
Jan 6 '06 #7

"Bob Barrows [MVP]" <re******@NOyahoo.SPAMcom> wrote in message
news:OC**************@TK2MSFTNGP10.phx.gbl...
Slim wrote:

ORDER BY
CASE WHEN
PATINDEX('%[^0-9]%',invoiceNumber)>0 THEN 999999999
ELSE CAST(invoiceNumber AS int) END,
invoiceNumber

Bob Barrows
would this give them to me before?

ORDER BY
CASE WHEN
CAST(invoiceNumber AS int)
ELSE PATINDEX('%[^0-9]%',invoiceNumber)>0 THEN 999999999 END,
invoiceNumber


No, this will raise an error, which you would have discovered if you had
taken the 30 seconds to actually try it ... ;-)

This is how it would be done:
ORDER BY
CASE WHEN
PATINDEX('%[^0-9]%',invoiceNumber)=0 THEN 'zzzzzzzzzz'
ELSE invoiceNumber END,
CASE WHEN
PATINDEX('%[^0-9]%',invoiceNumber)>0 THEN -1
ELSE CAST(invoiceNumber AS int) END

Bob Barrows


thank very much,



--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"

Jan 6 '06 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
5805
by: Klaus Petersen | last post by:
Hi ng. I have a varchar field in my table, called Name. I wanna do a selection, which is ordered by whether this field is empty or not. E.g. something like: SELECT
2
5227
by: Jeff Magouirk | last post by:
Dear All, I have written an update trigger that should write a message to an audit table When I try to update any field in the table I recieve the following error message - Stirng or...
32
2649
by: Indrid Colt | last post by:
Thank's for your help ! Indrid
35
75081
by: pinkfloydhomer | last post by:
How do I check if a string contains (can be converted to) an int? I want to do one thing if I am parsing and integer, and another if not. /David
23
15626
by: Abhi | last post by:
Hi.. I wanted the C source code in machine readable format for the book "Numerical Recipes in C". I got hold of the pdf version of the book somehow. Does anyone have the complete C code of the...
1
1899
by: Kevin Burton | last post by:
I have a set of XSD's that I would like to build some classes from. When I run the xsd tool I get a warning that the following is not "legal": <xsd:restriction base="xsd:string"> I have seen...
4
1969
by: Trapulo | last post by:
I've a webservice with a string parameter. I call this webservice passing a string that is 1129 chars length. On the webservice, the received string is 1146 length (I tested sizes with...
13
6851
by: bwaichu | last post by:
Now, I read the faq, and it suggests using sprintf. However, I want to all ways know where the integer finishes in the string. Basically, I want to: nbr | other data But the other data all...
7
3738
by: neovantage | last post by:
Hey all, I am creating a xml file in this format <?xml version="1.0" encoding="utf-8" standalone="yes"?> <customers> <customer> <category>Brosch&uuml;ren</category> ...
0
7124
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
6998
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
1
6884
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7375
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5460
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4904
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3078
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
651
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
287
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.