遍历某个指定的表

1.使用游标

 

Use Master

Declare My_cursor cursor for
select name,number
from dbo.spt_values
where number=1


declare @sname varchar(50)
declare @snumber varchar(50)

open My_cursor
fetch next from My_cursor into @sname,@snumber
while(@@fetch_status = 0)
Begin
 print @sname
 print @snumber

 fetch next from My_cursor into @sname,@snumber
End

close My_cursor
deallocate My_cursor

 

 

 

 

 

 

posted @ 2008-08-12 14:58  Simon.guo  阅读(154)  评论(0编辑  收藏  举报