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

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.


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

WEBINAR:

On-Demand

Application Security Testing: An Integral Part of DevOps


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