Solved

VB6 SQL Order By (Number)

Posted on 2010-09-03
9
201 Views
Last Modified: 2012-05-10
Hey,

Im looking for how to correctly order by a number.
At the moment, im getting results like:
1
10
11
2
3
4
etc...

How do I do it correctly?

Thanks,
Jessee
0
Comment
Question by:Letsgetcoding
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
9 Comments
 
LVL 53

Expert Comment

by:Dhaest
ID: 33594281
How are these numbers stored ? (I assume as a string). In what do you want to sort ?
Can you show us some code where you perform the sorting ?
0
 
LVL 53

Expert Comment

by:Dhaest
ID: 33594288
If it's on sqlserver, try something like this

SELECT
 ...
ORDER BY
  CASE  
    WHEN ISNUMERIC(value) = 1 THEN CONVERT(INT, value)  
    ELSE 9999999 -- or something huge
  END,
  value
0
 
LVL 96

Expert Comment

by:Lee W, MVP
ID: 33594289
Sounds like the field is text and not numeric.  I believe an ORDER BY CAST(DesiredField AS Integer) should work if I'm right... but if you want a more confident answer, you'll have to post some code and explain the datatypes of the fields you're using.
0
Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

 

Author Comment

by:Letsgetcoding
ID: 33594368
Hey,

.CommandText = "SELECT * FROM tblSongs WHERE colPlaylist= ? ORDER BY colPlaylistPos"

colPlaylistPos has a text datatype.
0
 
LVL 53

Expert Comment

by:Dhaest
ID: 33594376
Try the following

.CommandText = "SELECT * FROM tblSongs WHERE colPlaylist= ? ORDER BY CASE  WHEN ISNUMERIC(colPlaylistPos) = 1 THEN CONVERT(INT, colPlaylistPos)  ELSE 9999999 END"
0
 

Author Comment

by:Letsgetcoding
ID: 33594399
Method .execute of object _Command failed.
0
 
LVL 53

Expert Comment

by:Dhaest
ID: 33594406
What database are you using ?
0
 

Author Comment

by:Letsgetcoding
ID: 33594414
Access
0
 
LVL 53

Accepted Solution

by:
Dhaest earned 125 total points
ID: 33594517
.CommandText = "SELECT * FROM tblSongs WHERE colPlaylist= ? ORDERBY VAL(colPlaylistPos)  "
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

687 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question