Solved

order by alphabet-number

Posted on 2004-09-29
2
1,595 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
Comment Utility
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
Comment Utility
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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Introduction SQL Server Integration Services can read XML files, that’s known by every BI developer.  (If you didn’t, don’t worry, I’m aiming this article at newcomers as well.) But how far can you go?  When does the XML Source component become …
Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

772 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now