Getting Started with Adobe After Effects - Part 6: Motion Blur


Upload Image Close it
Select File

Browse by Tags · View All
sql_server 217
t-sql 211
tsql 116
sqlserver 96
BRH 78
#SQLServer 66
#TSQL 56
SQL Server 34
function 11
SSMS 9

Archive · View All
August 2007 17
August 2010 8
June 2012 7
June 2011 7
November 2007 7
August 2012 6
May 2012 6
November 2011 6
August 2011 6
October 2011 6

Madhivanan's TSQL Blog

Ordering Interger values stored in Varchar column

Jul 21 2008 2:20PM by Madhivanan   

I have seen many newbies asking "How do I sort the numbers stored in varchar columns?"

Here are some methods
declare @t table(data varchar(15))

insert into @t
select '6134' union all
select '144' union all
select '7345' union all
select '109812' union all
select '100074'union all
select '1290' union all
select '45764'

--Method 1 

select data from @t
order by cast(data as int)

--Method 2 

select data from @t
order by data+0

--Method 3 

select data from @t
order by len(data),data

--Method 4 

select data from @t
order by replace(str(data),' ','0')

--Method 5 

select data from @t
group by data
order by replicate('0',len(data)),data

--Method 6

select data from @t
order by replicate('0',(select max(len(data+0)) from @t)-len(data))+data 

--Method 7 
select data from @t
cross join
(
        select len(max(data+0)) as ln from @t
) as t
order by replicate('0',ln-len(data))+data 

Tags: t-sql, sql_server, varchar_sorting,


Madhivanan
3 · 40% · 12958
0
Liked
 
0
Lifesaver
 
0
Refreshed
 
0
Learned
 
0
Incorrect



Submit

Your Comment


Sign Up or Login to post a comment.

    Copyright © Rivera Informatic Private Ltd Contact us      Privacy Policy      Terms of use      Report Abuse      Advertising      [ZULU1097]