--分拆处理示例
create table table1(文章ID int,文章标题 varchar(10),作者 varchar(100),字数 int)
insert table1 select 101, '文章标题1 ', '作者a,作者b ' ,120
union all select 222, '文章标题2 ', '作者x,作者y,作者z ',300
union all select 343, '文章标题3 ', '作者m,作者n ' ,420
go
--分拆处理
declare @i int
select @i=max(len(作者)) from table1
set rowcount @i
select id=identity(int) into #t from syscolumns a,syscolumns b
set rowcount 0
select a.文章ID,a.文章标题
,作者=substring(a.作者,b.id,charindex( ', ',a.作者+ ', ',b.id)-b.id)
,字数=a.字数/(len(a.作者)-len(replace(a.作者, ', ', ' '))+1)
from table1 a,#t b
where b.id <=len(a.作者) and substring( ', '+a.作者,b.id,1)= ', '
go
--删除测试
drop table table1,#t