declare  cursor_insert cursor for select c# from cs
declare
@i int
open cursor_insert
fetch cursor_insert into @i
while @@fetch_status=0
begin
  print @i
  fetch cursor_insert into @i
end
close cursor_insert
deallocate cursor_insert

解决方案 »

  1.   

    use pubs----------选择
    godeclare dali_cursor scroll cursor for------------定义游标
    select * from jobs where max_lvl>100 ----------游标体查找语句
    open dali_cursor-----------------打开游标 -------fetch next from dali_cursor------------提取游标-----next---last
    close dali_cursor------------------关闭游标
    deallocate dali_cursor------------释放游标
      

  2.   

    你非要这样的话有游标吧
    USE pubs
    GO-- Declare the variables to store the values returned by FETCH.
    DECLARE @au_lname varchar(40), @au_fname varchar(20)
    DECLARE authors_cursor CURSOR FOR
    SELECT au_lname, au_fname FROM authors
    WHERE au_lname LIKE "B%"
    ORDER BY au_lname, au_fnameOPEN authors_cursor-- Perform the first fetch and store the values in variables.
    -- Note: The variables are in the same order as the columns
    -- in the SELECT statement. FETCH NEXT FROM authors_cursor
    INTO @au_lname, @au_fname-- Check @@FETCH_STATUS to see if there are any more rows to fetch.
    WHILE @@FETCH_STATUS = 0
    BEGIN   -- Concatenate and display the current values in the variables.
       PRINT "Author: " + @au_fname + " " +  @au_lname   -- This is executed as long as the previous fetch succeeds.
       FETCH NEXT FROM authors_cursor
       INTO @au_lname, @au_fname
    ENDCLOSE authors_cursor
    DEALLOCATE authors_cursor
    GO