SQL Server游标循环读取

declare @DJBH varchar(50)
declare @DM2 varchar(50)
declare @SQLText varchar(3000)
declare myCursor cursor for select top 10 DJBH from SPJHD ORDER BY DJBH
open myCursor
fetch next from myCursor into @DJBH
while @@fetch_status=0
  begin
    print 'CategoryId='+cast(@DJBH as varchar(20))
    Set @SQLText =
    'Select DM2 From SPJHD Where DJBH=' + ''''+@DJBH+''''
    print @SQLText
    fetch next from myCursor into @DJBH
  end
close myCursor
deallocate myCursor



SELECT * FROM SPJHD

 

posted on 2013-04-13 16:35  哈哈哈哈BBA  阅读(331)  评论(0编辑  收藏  举报

导航