SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 An "order by" issue..
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

gsrinivas.
Yak Posting Veteran

56 Posts

Posted - 10/26/2012 :  14:31:11  Show Profile  Reply with Quote
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
Flowing Fount of Yak Knowledge

5155 Posts

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

gsrinivas.
Yak Posting Veteran

56 Posts

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

sunitabeck
Flowing Fount of Yak Knowledge

5155 Posts

Posted - 10/27/2012 :  08:49:35  Show Profile  Reply with Quote
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 - 10/27/2012 :  12:48:06  Show Profile  Reply with Quote
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.


Edited by - gsrinivas. on 10/27/2012 13:03:10
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.07 seconds. Powered By: Snitz Forums 2000