Sql Server臨時表、表変数、関数の代替
3235 ワード
http://www.cnblogs.com/chongzi/archive/2011/01/19/1939106.html
臨時表
tempdbに保存する
-- ,
--
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