Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 An "order by" issue..

Author  Topic 

gsrinivas.
Yak Posting Veteran

56 Posts

Posted - 2012-10-26 : 14:31:11
Hi team,
I have an issue with order by clause..
plz suggest me the query..

Thanks in advance...
-Srinivas.






-----------************************************--------------
INPUT
-----------************************************--------------
CREATE TABLE T ( C1 VARCHAR(20),C2 VARCHAR(20))

INSERT INTO T VALUES ('ALFABET','A')
INSERT INTO T VALUES ('ALFABET','B')
INSERT INTO T VALUES ('ALFABET','C')

INSERT INTO T VALUES ('NUBER','1')
INSERT INTO T VALUES ('NUBER','2')
INSERT INTO T VALUES ('NUBER','3')
INSERT INTO T VALUES ('NUBER','4')

INSERT INTO T VALUES ('SYMBOL','+')
INSERT INTO T VALUES ('SYMBOL','-')

-----------************************************--------------
OUTPUT
-----------************************************--------------
Now the output should be as follows...

NUBER 1
NUBER 2
NUBER 3
NUBER 4
ALFABET A
ALFABET B
ALFABET C
SYMBOL +
SYMBOL -

sunitabeck
Master Smack Fu Yak Hacker

5155 Posts

Posted - 2012-10-26 : 14:47:29
[code]ORDER BY
CASE c1
WHEN 'NUBER' THEN 1
WHEN 'ALFABET' THEN 2
WHEN 'SYMBOL' THEN 3
END,
c2;[/code]
Go to Top of Page

gsrinivas.
Yak Posting Veteran

56 Posts

Posted - 2012-10-27 : 06:34:50
Here I mentioned only sample data only..
but I don't know how many groups there are..
Go to Top of Page

sunitabeck
Master Smack Fu Yak Hacker

5155 Posts

Posted - 2012-10-27 : 08:49:35
If there are other groups, what is the rule that should be followed? If it is all numeric followed by all alphas followed by all symbols, then use the approach Rob Volk had described in the duplicate issue you posted: http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=180127

If it is some other rules that need to be followed for ordering, can you describe the rule?

BTW, people who run this forum look upon duplicate posts advise against duplicate posting - for avoiding fragmentation of replies, for avoiding multiple people wasting their time trying to solve the same problem etc.
Go to Top of Page

gsrinivas.
Yak Posting Veteran

56 Posts

Posted - 2012-10-27 : 12:48:06
quote:
Originally posted by sunitabeck

If there are other groups, what is the rule that should be followed? If it is all numeric followed by all alphas followed by all symbols, then use the approach Rob Volk had described in the duplicate issue you posted: http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=180127

If it is some other rules that need to be followed for ordering, can you describe the rule?

BTW, people who run this forum look upon duplicate posts advise against duplicate posting - for avoiding fragmentation of replies, for avoiding multiple people wasting their time trying to solve the same problem etc.



Hi sunitabeck,
Sorry for duplicate posting..Actually I posted this first in 2000 forum.After that I realized that there are no frequent postings in now a days.So I created again in this forum..

Thanks for advice.
-Srinivas.

Go to Top of Page
   

- Advertisement -