如何将查询结果插入表中,如:
;with foo(foo1,foo2) as (
...
from ...
select from foo
where ...
)
select [1],[2],[3],...,[n]
from
(
select from foo f
) p
pivot () pv
order by row
答案 0 :(得分:1)
这就是你想要的:
;with foo(foo1,foo2)
as
( ...from ... select from foowhere ...)
插入#SomeTable
select [1],[2],[3],...,[n]
from(
select from foo f) ppivot () pv order by row
答案 1 :(得分:0)
答案很接近,解决方案是:
;with foo(foo1,foo2)
as
(
...from ... select from foowhere
...
)
select [1],[2],[3],...,[n] INTO #SomeTable
from(
select from foo f
) ppivot (...) pv
order by row