declare @y1002 varchar(200),@a0100 varchar(200),@c0103 datetime ----定义变量 declare police_department cursor for --定义游标 select y1002,a0100,c0103 from a001a000 where left(y1002,1)='4' and laborstate=1 ---查询的数据 open police_department --打开游标 fetch next from police_department into @y1002,@a0100,@c0103 --将游标向下移1行,获取的数据放入之前定义的变量@@y1002,@a0100,@c0103中,这个支段的数量要与查出的支段数量一致 while @@fetch_status=0 --判断是否成功获取数据 begin -----这里写代码逻辑块 fetch next from police_department into @y1002,@a0100,@c0103 --将游标向下移1行 end close police_department --关闭游标 deallocate police_department --释放游标 ---游标可用于循环