遊標使用

 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

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章