declare @tablename varchar(8000)
declare @gsid int
--定義遊標
declare c1 cursor for
select company_id from dbo.gq where gsid is null
--打開遊標
open c1
--從遊標獲取數據
fetch next from c1 into @tablename
--遊標打開ok
WHILE @@fetch_status=0
BEGIN
編寫代碼
--從遊標獲取下一項數據
FETCH NEXT FROM c1 INTO @tablename
END
--關閉遊標
CLOSE c1
--釋放遊標
deallocate c1