SqlServer中临时表的使用

 

http://www.cnblogs.com/chongzi/archive/2011/01/19/1939106.html

 

--存储过程中将多表连接结果写入到临时表中,然后通过游标查询临时表内容  
--判断临时表是否存在
IF    OBJECT_ID(tempdb..#TmpTable‘) IS NOT NULL
DROP TABLE #TmpTable

SELECT a.[a1],a.[a1],b.[b1],b.[b2]
INTO #TmpTable
FROM A a
LEFT JOIN B b ON a.a1 = b.a1

 

操作游标

DECLARE @orderId NVARCHAR(50),@customerId NVARCHAR(50),@employeeId NVARCHAR(50)
DECLARE myCursor CURSOR FOR
SELECT o.OrderID,o.CustomerID,o.EmployeeID FROM Orders AS o

OPEN myCursor
fetch next from myCursor into @orderId,@customerId,@employeeId
while @@fetch_status=0 
BEGIN

PRINT @orderId
PRINT @customerId
PRINT @employeeId
fetch next from myCursor into @orderId,@customerId,@employeeId
END
close myCursor 
deallocate myCursor

 

SqlServer中临时表的使用,古老的榕树,5-wow.com

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。