Solved

order by alphabet-number

Posted on 2004-09-29
2
1,616 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
2 Comments
 
LVL 143

Assisted Solution

by:Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3] earned 100 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 100 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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.

829 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