开发者

order by word in SQL [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 11 years ago.

For E.g

I have word "John Roshan" i want to arrange this order by first 开发者_运维百科alphbet of the each word that means the output of the above word should be "Roshan John".

I want to do it with SQL

Please help me its urget.

Thanks in advance


declare @S varchar(50)
set @S = 'John Roshan 2000'

;with cte as
(
  select 
    1 as P1,
    charindex(' ', @S+' ', 1) as P2
  union all
  select
    C.P2+1,
    charindex(' ', @S+' ', C.P2+1) as P2
  from cte as C
  where charindex(' ', @S+' ', C.P2+1) > 0
)

select
(
  select substring(@S, P1, P2-P1)+' '
  from cte
  order by substring(@S, P1, P2-P1)
  for xml path(''), type
).value('.', 'varchar(50)')  
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜