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 2005 Forums
 Transact-SQL (2005)
 Ordering output

Author  Topic 

eddy556
Starting Member

36 Posts

Posted - 2009-01-16 : 06:21:22
Now I know this looks simple at first glance but I need your ideas.

I have a stored procedure which output data similar to the following:

Consider urine checks (reg11),
If usingengineering controls/non disposable RPE ensure maintenance(reg 9),
Consider monitoring (reg 10),
Consider end tidal breath tests (Reg 11).

I need to order them based on the (Reg xx) ASC

There are no other values by which I can order them (i.e. textcode or whatever) so the only other way I can see is somehow parse the xx bit out and order via that?

Jai Krishna
Constraint Violating Yak Guru

333 Posts

Posted - 2009-01-16 : 06:24:58
ORDER BY CAST(RIGHT(RTRIM(col),2) AS INT)

OR

ORDER BY CONVERT(INT, RIGHT(RTRIM(col),2))

OR

ORDER BY CAST (SUBSTRING(col,CHARINDEX(' ',col,1)+1,LEN(col)) AS INT)
col is ur column name which contains reg 10.........

Jai Krishna
Go to Top of Page

eddy556
Starting Member

36 Posts

Posted - 2009-01-16 : 06:32:37
WOW you guys know your stuff! Many thanks!
Go to Top of Page

Jai Krishna
Constraint Violating Yak Guru

333 Posts

Posted - 2009-01-16 : 06:38:11
Welcome

Jai Krishna
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-01-16 : 07:18:50
or

ORDER BY RIGHT(RTRIM(col),2)*1


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -