我想引用#temptable的第n行(在第二個SQL註釋如下)。什麼樣的表達可以讓我這麼做?在T-SQL/SQL Server 2000中,引用結果集的特定行
DECLARE @counter INT
SET @counter = 0
WHILE (@counter<count(#temptable))
--#temptable has one column and 0 or more rows
BEGIN
DECLARE @variab INT
EXEC @variab = get_next_ticket 3906, 'n', 1
INSERT INTO Student_Course_List
SELECT @student_id,
-- nth result set row in #temptable, where n is @count+1
@variab
SET @counter = @counter +1
END
光標(將這項工作?):
for record in (select id from #temptable) loop
--For statements, use record.id
end loop;
基於什麼邏輯? – JNK
遍歷#temptable行。以下語法是否適用於SQL Server 2000? 用於記錄(從#temptable中選擇col_1)循環 /*語句,使用record.col_1 */ end loop; – ppecher
@ppecher是Cursor適用於每個循環(但語法稍微複雜一些,請參閱我的msdn文檔鏈接)。他們使用SQL 2000. – Magnus