declare @sqlExec varchar(8000),@tableName varchar(255)
set @tableName = 'sysobjects'
set @sqlExec = 'declare cursor1 cursor for ' + CHAR(13)
set @sqlExec = @sqlExec + ' select * from ' + @tableName
exec(@sqlExec)
open cursor1
fetch next from cursor1 ---如果要放在變量中請寫into <變量列表>
while @@fetch_status = 0
......
fetch next from cursor1 ---如果要放在變量中請寫into <變量
end
close cursor1
deallocate cursor1