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 |
|
lols
Posting Yak Master
174 Posts |
Posted - 2008-04-17 : 07:48:30
|
| Hi,I have a column containing data3 KB16 KB2 KB4 KB43 KBHow to sort this column and display results like:4316432Thanks. |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2008-04-17 : 07:49:24
|
select col1, replace(col1, ' kb', '') from table1 E 12°55'05.25"N 56°04'39.16" |
 |
|
|
lols
Posting Yak Master
174 Posts |
Posted - 2008-04-17 : 07:54:52
|
| Hi,Thanks. My Column containing that data is a varchar(20). How do I sort it? It is not giving correct results. |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2008-04-17 : 07:56:12
|
select *from table1order by len(col1), col1 E 12°55'05.25"N 56°04'39.16" |
 |
|
|
lols
Posting Yak Master
174 Posts |
Posted - 2008-04-17 : 07:56:58
|
I did this:SELECT col1, replace(col1, ' kb', '') as newcolfrom Size order by newcol descbut results are like this:120 KB 120144 KB 14416 KB 1616 KB 1616 KB 1616 KB 1616 KB 1616 KB 16264 KB 264288 KB 28832 KB 3232 KB 32336 KB 336456 KB 45664 KB 648 KB 88 KB 88 KB 88 KB 88 KB 88 KB 88 KB 88 KB 88 KB 88 KB 88 KB 88 KB 88 KB 88 KB 88 KB 88 KB 88 KB 88 KB 88 KB 88 KB 88 KB 88 KB 88 KB 88 KB 88 KB 88 KB 88 KB 88 KB 88 KB 88 KB 88 KB 88 KB 88 KB 88 KB 88 KB 88 KB 88 KB 88 KB 88 KB 88 KB 88 KB 88 KB 88 KB 88 KB 88 KB 8 |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2008-04-17 : 07:57:28
|
[code]DECLARE @Sample TABLE (myData VARCHAR(20))INSERT @SampleSELECT '3 KB' UNION ALLSELECT '16 KB' UNION ALLSELECT '2 KB' UNION ALLSELECT '4 KB' UNION ALLSELECT '43 KB'SELECT myDataFROM @SampleORDER BY LEN(myData) DESC, myData DESC[/code] E 12°55'05.25"N 56°04'39.16" |
 |
|
|
lols
Posting Yak Master
174 Posts |
Posted - 2008-04-17 : 08:00:46
|
| thanks peso for the help. i also did it using CAST.:) |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2008-04-18 : 05:20:33
|
orSELECT myDataFROM @SampleORDER BY substring(mydata,1,charindex(' ',mydata)-1)*1 descMadhivananFailing to plan is Planning to fail |
 |
|
|
|
|
|
|
|