是否有更有效的方法來編寫此代碼?或者用更少的代碼?更快地更新SQL Server表中的所有行
SELECT *
INTO #Temp
FROM testtemplate
Declare @id INT
Declare @name VARCHAR(127)
WHILE (SELECT Count(*) FROM #Temp) > 0
BEGIN
SELECT TOP 1 @id = testtemplateid FROM #Temp
SELECT TOP 1 @name = name FROM #Temp
UPDATE testtemplate
SET testtemplate.vendortestcode = (SELECT test_code FROM test_code_lookup WHERE test_name = @name)
WHERE testtemplateid = @id
--finish processing
DELETE #Temp Where testtemplateid = @id
END
DROP TABLE #Temp
見http://stackoverflow.com/questions/1293330/how-can-i-do-an-update-statement-with-join-in-sql爲一個關於如何做到這一點的指針,雖然喬是正確的(+1)(並且在打字時比我更快!) – dash 2011-12-19 15:55:52