Solved

order by alphabet-number

Posted on 2004-09-29
2
1,610 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 142

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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

Suggested Solutions

Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
I have a large data set and a SSIS package. How can I load this file in multi threading?
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

773 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