編集 元の回答は要件を誤解していました。修正をボッジしましたが、キャラクター レベルへの分割は完全に不要になりました。少なくとも、いくつかのアイデアが得られるかもしれません!
WITH Strings AS
(
select 'A Student' as String
UNION ALL
select 'blah' as String
UNION ALL
select 'the quick brown fox jumped over the lazy dog' as String
),
SplitChars As
(
SELECT ROW_NUMBER() OVER (ORDER BY number) AS number, String, SUBSTRING(String,number,1) AS Ch FROM Strings
JOIN master.dbo.spt_values on number BETWEEN 1 AND LEN(String) AND type='P'
)
SELECT String,
replace(Stuff(
(
Select '' + Ch
From SplitChars SC3
WHERE SC3.String = SC.String
Order By (SELECT COUNT(*) FROM SplitChars SC2 WHERE SC2.String = SC3.String AND SC2.Ch = ' ' AND SC2.number < SC3.number) desc, case when SC3.ch = ' ' then -1 else number end
For Xml Path('')
),1, 0, ''), ' ', ' ') AS Reversed
FROM SplitChars SC
GROUP BY String
返品
- 学生A
- まあ
- 犬の怠け者、飛び越えたキツネ、茶色の素早い