日期:2014-05-17 浏览次数:20615 次
create table hp
(ID int, nick varchar(14), content varchar(16),
Forum int, theTime datetime)
insert into hp
select 1, '030709200876', 'aaa#bbb#ccc##', 1, '2012-10-15 17:54:14.000' union all
select 2, '030709200876', 'AAA##BBB##', 2, '2012-10-16 14:56:32.000'
select a.ID,a.nick,
substring(replace(a.content,'##','#'),b.number,
charindex('#',replace(a.content,'##','#'),b.number)-b.number) 'content',
a.Forum,a.theTime
from hp a
inner join master.dbo.spt_values b
on b.number<=len(replace(a.content,'##','#')) and b.type='P'
where substring('#'+replace(a.content,'##','#'),b.number,1)='#'
/*
ID nick content Forum theTime
----------- -------------- ---------- ----------- -----------------------
1 030709200876 aaa 1 2012-10-15 17:54:14.000
1 030709200876 bbb 1 2012-10-15 17:54:14.000
1 030709200876 ccc 1 2012-10-15 17:54:14.000
2 030709200876 AAA 2 2012-10-16 14:56:32.000
2 030709200876 BBB 2 2012-10-16 14:56:32.000
(5 row(s) affected)
*/