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 |
|
cnbhold
Starting Member
43 Posts |
Posted - 2010-07-15 : 13:06:22
|
| I have a varchar field that contains the following data1.x2.x3.x4.x5.x6.x7.x8.x9.x10.x11.x12.x13.xI need to write a SQL query that will sort the field in DESC order 13.x12.x11.x10.x9.x8.x7.x6.x5.x4.x3.x2.x1.x |
|
|
pk_bohra
Master Smack Fu Yak Hacker
1182 Posts |
Posted - 2010-07-15 : 13:08:49
|
| Did you try "Order by " <column> desc.Can you post some sample data and expected output ? |
 |
|
|
cnbhold
Starting Member
43 Posts |
Posted - 2010-07-15 : 13:12:16
|
| Here's my query and outputselect numberfrom versionorder by number descQuery Output9.x8.x7.x6.x5.x4.x3.x2.x12.x11.x10.x1.x |
 |
|
|
pk_bohra
Master Smack Fu Yak Hacker
1182 Posts |
Posted - 2010-07-15 : 13:29:11
|
| Try this:I am assuming that there will always be a '.' in the field. If this is not the case then let us know so that the solution can be modified.select number from version order by cast(left(number, charindex('.',number) -1) as int) descRegards,BohraI am here to learn from Masters and help new bees in learning. |
 |
|
|
cnbhold
Starting Member
43 Posts |
Posted - 2010-07-15 : 13:35:57
|
| Bohra, Thanks!!!! That worked... |
 |
|
|
pk_bohra
Master Smack Fu Yak Hacker
1182 Posts |
Posted - 2010-07-15 : 23:25:47
|
quote: Originally posted by cnbhold Bohra, Thanks!!!! That worked...
You are welcome I am here to learn from Masters and help new bees in learning. |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2010-07-16 : 11:25:25
|
| If all the numbers end with .x,select numberfrom versionorder by replace(number,'.x')*1 descMadhivananFailing to plan is Planning to fail |
 |
|
|
|
|
|