我想引用#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