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.
| Author |
Topic |
|
kamii47
Constraint Violating Yak Guru
353 Posts |
Posted - 2010-09-25 : 03:16:26
|
| I have Data in a varchar field of my table as 1fgh102354672089301121I wants its result with by order by in the way that frist numeric record will come in order then alphabetics like1234567891011202130fghKamran ShahidSr. Software Engineer(MCSD.Net,MCPD.net) |
|
|
Sachin.Nand
2937 Posts |
Posted - 2010-09-25 : 04:20:44
|
Isn't just this enough?select * from yourtable order by your ordercolumn Does your column contain alphanumeric characters?PBUH |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2010-09-25 : 12:32:47
|
| [code]select * from yourtable ORDER BY CASE WHEN ISNUMERIC(yourcol)=1 THEN 1ELSE 2END,Len(yourcol),yourcol asc[/code]------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
robvolk
Most Valuable Yak
15732 Posts |
Posted - 2010-09-25 : 14:17:20
|
quote: select * from yourtable ORDER BY CASE WHEN ISNUMERIC(yourcol)=1 THEN 1ELSE 2END,Len(yourcol),yourcol asc
Decimals and exponents (1E38, 1E-10) could throw that off, this may be better:select * from yourtable ORDER BY CASE WHEN ISNUMERIC(yourcol)=1 THEN 1ELSE 2 END,CASE WHEN ISNUMERIC(yourcol)=1 THEN cast(yourcol as float) END,yourcol asc |
 |
|
|
|
|
|