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
 SQL Server 2000 Forums
 SQL Server Development (2000)
 An "order by" issue..

Author  Topic 

gsrinivas.
Yak Posting Veteran

56 Posts

Posted - 2012-10-26 : 14:05:42
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

15732 Posts

Posted - 2012-10-26 : 14:14:22
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

52326 Posts

Posted - 2012-10-26 : 15:08:04
duplicate of

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

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

Go to Top of Page
   

- Advertisement -