小弟有一段SQL如下
if object_id('tempdb..#temptable')>0
drop table #temptable
select * into #temptable
from (select A,B
from table1
union
select A,B
from table2) temp
select A, B=stuff((select ' '+B from #temptable t where A=#temptable.A for xml path('')), 1, 0, '') 
from #temptable 
group by A因为要对数据做合并,定义了一个临时表#temptable,SQL在查询环境能运行,但在EXcel里面无法运行,不能识别临时表,怎么能不用临时表实现同样的合并功能, A字段相同的记录,合并B字段 ,记录首先是从两个表table1,table2联合查询出来的,再对查询结果做合并。