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 |
sigmas
Posting Yak Master
172 Posts |
Posted - 2013-01-11 : 08:56:26
|
Hi,I need to resort(order asc) words in a string.declare @s varchar(50) = 'one two three four seven nine'The string must be after sorting like this:'four nine one seven three two'Is a simple method? |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-01-11 : 09:05:17
|
[code]declare @s varchar(50) = 'one two three four seven nine'declare @sorder varchar(50)SELECT @sorder= COALESCE(@sorder,'') + Val + ' 'FROM dbo.ParseValues(@s,' ') fSELECT @sorder[/code]------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
|
sigmas
Posting Yak Master
172 Posts |
Posted - 2013-01-11 : 09:31:52
|
Thanks,similar to [url]http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=182028[/url]Posted - 01/11/2013 : 09:16:29 even word be sorted the query split all of strings, or just two first words need to order... . |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-01-11 : 09:34:34
|
quote: Originally posted by sigmas Thanks,similar to [url]http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=182028[/url]Posted - 01/11/2013 : 09:16:29 even word be sorted the query split all of strings, or just two first words need to order... .
sorry i dont understand your explanationcan you elaborate?------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
|
|
sigmas
Posting Yak Master
172 Posts |
Posted - 2013-01-11 : 09:39:29
|
for example we want sort this:'b a c d e f g h i j k'Only 'a' and 'b' need to exchange but your query split all string then sort them. |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-01-11 : 10:16:59
|
how do you know only a and b are out of order unless you parse it. so you've to parse the entire string anyway using any of the methods------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
|
|
|
|
|