日期:2014-05-18 浏览次数:20647 次
--写完才看到是 2000 ,就贴个 2005 的 declare @t table(a varchar(10),b varchar(20)) insert into @t select 'pp' ,'pp1' union all select 'kk' ,'kk 1/kk 2' union all select 'hh' ,'hh 1/hh 2/hh 3/hh 4' select a.a,b.b from( select a,[value] = convert(xml,'<v>' + REPLACE(b, '/', '</v><v>') + '</v>') from @t ) a outer apply( select b = N.v.value('.', 'varchar(100)') from a.[value].nodes('/v') N(v) ) b /************************* a b ---------- ---------------------------------------------------------------- pp pp1 kk kk 1 kk kk 2 hh hh 1 hh hh 2 hh hh 3 hh hh 4 (7 行受影响)
------解决方案--------------------
--2000 declare @t table(a varchar(10),b varchar(20)) insert into @t select 'pp' ,'pp1' union all select 'kk' ,'kk 1/kk 2' union all select 'hh' ,'hh 1/hh 2/hh 3/hh 4' select a.a,substring(a.b,b.number,charindex('/',a.b+'/',b.number)-b.number) b from @t a ,master..spt_values b where b.[type] = 'P' and b.number between 1 and len(a.b) and substring('/'+a.b,b.number,1) = '/' /******************** a b ---------- -------------------- pp pp1 kk kk 1 kk kk 2 hh hh 1 hh hh 2 hh hh 3 hh hh 4 (7 行受影响)
------解决方案--------------------
你可以自已写一个 函数,跟 split 作用一样
http://blog.csdn.net/peng13nannan/article/details/7418927