Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language: SQL Server
Expertise: Beginner
Jan 8, 1999

Order by

Question:
I can't sort by the second-last digit of a number (for example, sorting the numbers 4491, 1195, and 1364 by the third digit).

Answer:
Try using the "RIGHT" function to order the numbers. If they are stored as integers, you will first have to convert them to character. Here's the code I used:


use scratch
go
create table #test
(
	x int
)

insert into #test values(4491)
insert into #test values(1195)
insert into #test values(1364)
insert into #test values(111)


select x
from #test
order by right(cast(x as char(8)),2)



drop table #test
DevX Pro
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date