SQL中的迴圈寫法之一。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--宣告變數 | |
DECLARE @ID varchar(8) | |
--取得ID列表 | |
DECLARE TEST_cursor1 CURSOR LOCAL FOR | |
SELECT ID FROM TABLE | |
--將ID參數置入@ID | |
OPEN TEST_cursor1 | |
FETCH NEXT FROM TEST_cursor1 INTO @ID | |
IF @@FETCH_STATUS = 0 | |
BEGIN | |
WHILE @@FETCH_STATUS = 0 | |
BEGIN | |
--迴圈中要執行的方法 | |
--UPDATE sample | |
UPDATE TABLE2 | |
SET ID = @ID | |
--移到下一個ID值 | |
FETCH NEXT FROM TEST_cursor1 INTO @ID | |
END | |
END | |
CLOSE TEST_cursor1 | |
DEALLOCATE TEST_cursor1 |
沒有留言:
張貼留言