问题描述
是否有创建类似于CTE的临时视图的方法,但是可以在存储过程中的多个语句中使用它吗?像这样:
create procedure dosomething as
begin
create view #temp as select ... ;
Statement 1 with #temp;
Statement 2 with #temp;
Statement 3 with #temp;
end;
解决方法
您可以将视图的结果放入临时表中,例如
SELECT A.*,B.*
INTO #TempTable
FROM A INNER JOIN B ON A.ID = B.ID
那应该做您所需要的,而无需多次运行视图?