Solved

SQL Syntax

Posted on 2012-03-28
5
341 Views
Last Modified: 2012-06-21
I am trying to order my recordset by the last 1 or 2 numbers from a value that always starts with a letter.  For example the value is B10, I want to order it by 10.

So what is the syntax for this in ORDER BY?

Here is the sql.  The ORDER BY row has psuedo code.

 strSql = "SELECT ServCat, Number, Division, Coded, Reason, ServCatDesc " _
    & "FROM tblServCats " _
    & "WHERE Div = '" & vDiv & "' " _
    & "ORDER BY  mid(ServCat , 1, 2)"

Thanks,
Scott
0
Comment
Question by:Scott Palmer
[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
  • 2
  • 2
5 Comments
 
LVL 61

Expert Comment

by:mbizup
ID: 37777972
Pad it with zeros to make sure it orders numerically - and I think you might need a corresponding SELECT column for the Order BY:

strSql = "SELECT ServCat, Format(mid(ServCat , 1, 2),'000000') AS SortingColumn, Number, Division, Coded, Reason, ServCatDesc " _
    & "FROM tblServCats " _
    & "WHERE Div = '" & vDiv & "' " _
    & "ORDER BY  Format(mid(ServCat , 1, 2),'000000')"
0
 
LVL 75

Accepted Solution

by:
DatabaseMX (Joe Anderson - Microsoft MVP, Access and Data Platform) earned 500 total points
ID: 37777979
Try this

& "ORDER BY  CLng(mid([ServCat] , 2))"
0
 
LVL 61

Expert Comment

by:mbizup
ID: 37777994
Sorry - try this:

strSql = "SELECT ServCat, Format(mid(ServCat , 2),'000000') AS SortingColumn, Number, Division, Coded, Reason, ServCatDesc " _
    & "FROM tblServCats " _
    & "WHERE Div = '" & vDiv & "' " _
    & "ORDER BY  Format(mid(ServCat , 2),'000000')"
0
 

Author Closing Comment

by:Scott Palmer
ID: 37778000
Beautiful.  Thanks.
0
 
LVL 75
ID: 37778024
You are welcome ...
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This article describes two methods for creating a combo box that can be used to add new items to the row source -- one for simple lookup tables, and one for a more complex row source where the new item needs data for several fields.
Microsoft Access is a place to store data within tables and represent this stored data using multiple database objects such as in form of macros, forms, reports, etc. After a MS Access database is created there is need to improve the performance and…
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

632 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