日期:2014-05-18  浏览次数:20516 次

列装行后如何将结果放入一个表里
请教大侠们一个问题,像列装行的写法
select Ltyp,stuff((select ','+Lname from #SQltemp b where a.Ltyp=b.Ltyp order by Lname for xml path('')),1,1,'')
from #SQltemp a
group by Ltyp



如何把得到的结果,如何存入另一个表里

------解决方案--------------------
SQL code
 insert into 另表
  select Ltyp,
  stuff((select ','+Lname from #SQltemp b where a.Ltyp=b.Ltyp order by Lname for xml path('')),1,1,'') from #SQltemp a group by Ltyp

------解决方案--------------------
SQL code

insert into tb
select Ltyp,stuff((select ','+Lname from #SQltemp b where a.Ltyp=b.Ltyp order by Lname for xml path('')),1,1,'')
from #SQltemp a
group by Ltyp

--or

select Ltyp,stuff((select ','+Lname from #SQltemp b where a.Ltyp=b.Ltyp order by Lname for xml path('')),1,1,'')
    into tb
from #SQltemp a
group by Ltyp