日期:2014-05-17 浏览次数:20420 次
declare @s varchar(1000)
set @s='CABDKZSVX'
select chr
from
(
select substring(chr,number+1,1) as chr
from (select @s as chr)a,master..spt_values
where type='P' and number<len(chr)
)t
order by chr
/*
chr
------------------------
A
B
C
D
K
S
V
X
Z
*/
declare @x varchar(10),@y varchar(10)
select @x='CABD'
select @y=cast(
(select ''+c from
(select substring(@x,number,1) 'c'
from master.dbo.spt_values
where type='P' and number between 1 and len(@x)) t
order by c for xml path('')) as varchar(10))
select @y 'y'
/*
y
----------
ABCD
(1 row(s) affected)
*/
WITH a1 AS
(
SELECT 'CABD' cstr
)
,a2 AS
(
SELECT cstr,SUBSTRING(cstr,1,1) cstr2,1 n FROM a1
UNION ALL
SELECT cstr,SUBSTRING(cstr,n+1,1),n+1 FROM a2
WHERE n+1<=LEN(cstr)
)
SELECT cstr=(SELECT ''+cstr2 FROM a2 ORDER BY cstr2 FOR XML PATH(''))
declare @t varchar(300)
set @t= 'CABD'
;with t
as
(
select @t as col,
substring(@t,s.number,1) as v
from master..spt_values s
where s.number >=1
and s.type = 'P'
and s.number <= LEN(@t)
)
select distinct
&