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
 SQL Server 2000 Forums
 SQL Server Development (2000)
 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:05:42  Show Profile  Reply with Quote
Hi team,
I have an issue with order by clause..
plz suggest me the best 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 -

robvolk
Most Valuable Yak

USA
15681 Posts

Posted - 10/26/2012 :  14:14:22  Show Profile  Visit robvolk's Homepage  Reply with Quote
SELECT * FROM T
ORDER BY CASE WHEN C2 LIKE '%[0-9]' THEN 0 ELSE 1 END,
CASE WHEN C2 LIKE '%[A-Z]' THEN 0 ELSE 1 END,
CASE WHEN C2 LIKE '%[^0-9A-Z]' THEN 0 ELSE 1 END,
C2
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52325 Posts

Posted - 10/26/2012 :  15:08:04  Show Profile  Reply with Quote
duplicate of

http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=180128

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

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.25 seconds. Powered By: Snitz Forums 2000