?
Solved

order by alphabet-number

Posted on 2004-09-29
2
Medium Priority
?
1,628 Views
Last Modified: 2008-01-16
I have a sql statement as follows:

Select       Client, sum(Amt1) as A, sum(Amt2) as B
from       Mytable
where       test = '76’
group by Client
order by substring(Client,2,1)

which returns something like this:

Client      A      B
M1      626      4
J1      1800      42
L1      1425      25
K1      1028      16
K2      566      11
M2      247      1
J2      794      4
L2      708      6
K3      282      9
J3      392      10
L3      331      6
M3      134      2
K4      173      2
M4      27      0
J4      216      1
L4      193      13
M5      13      0
J5      41      1
L5      65      2
K5      32      0

 Ok,This returns all the 1’s , 2’s, 3’s and so on together for the Client, but doesn’t come out in alphabetical order.  How do I make it to return alphabetically -number(in Client )? Like as follows

Client
J1
K1
L1
M1
J2
K2
L2
M2
.
.
.
and so on.

Any help would be appreciated. Thanks

PP
0
Comment
Question by:pmandair
[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 Comments
 
LVL 143

Assisted Solution

by:Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3] earned 300 total points
ID: 12180605
Select      Client, sum(Amt1) as A, sum(Amt2) as B
from      Mytable
where      test = '76’
group by Client
order by substring(Client,2,1), substring(client,1,1)

Cheers
0
 
LVL 17

Accepted Solution

by:
BillAn1 earned 300 total points
ID: 12180615
try
Select      Client, sum(Amt1) as A, sum(Amt2) as B
from      Mytable
where      test = '76’
group by Client
order by substring(Client,2,1), client
0

Featured Post

Get MongoDB database support online, now!

At Percona’s web store you can order your MongoDB database support needs in minutes. No hassles, no fuss, just pick and click. Pay online with a credit card. Handle your MongoDB database support now!

Question has a verified solution.

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

This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
Suggested Courses

800 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