日期:2014-05-18 浏览次数:20839 次
create table ion
(A int,B int,C varchar(8),D int)
insert into ion
select 1, 2, 'hello', 3 union all
select 1, 3, 'hello', 3 union all
select 1, 4, 'no', 3 union all
select 1, 3, 'kkk', 4 union all
select 2, 2, 'kkk', 3
create view vion as
select t1.A 'E',
stuff((select ',文件'+cast(B as varchar)+' 错误'+C
from ion t2 where t2.A=t1.A and t2.D=t1.D
for xml path('')),1,1,'') 'F',
t1.D 'G' from ion t1 group by t1.A,t1.D
select * from vion
E F G
----------- ---------------------------------------------- -----------
1 文件2 错误hello,文件3 错误hello,文件4 错误no 3
1 文件3 错误kkk 4
2 文件2 错误kkk 3
(3 row(s) affected)