sqlserver游标使用
declare empi_cursor cursor scroll --创建游标
for select top 50 YLJGDM,GRJBXXBSH,XGBZ,"2" AS SJLY,KLXDM as KLX,KH,ZJLXDM as ZJLX, ZJHM,XM FROM DA_GR_JBXX(nolock) where SYZT="0"
OPEN empi_cursor --打开游标
DECLARE @zjlx varchar(2) --声明变量 ‘DECLARE’为声明变量 ‘@name’为变量名称 后面为变量类型
DECLARE @zjhm varchar(32)
DECLARE @klx varchar(16)
DECLARE @kh varchar(64)
DECLARE @sjly varchar(1)
DECLARE @xm varchar(30)
DECLARE @yljgdm varchar(22)
DECLARE @grjbxxbsh varchar(64)
DECLARE @xgbz varchar(1)
DECLARE @lybm varchar(20)
FETCH NEXT FROM empi_cursor into @yljgdm,@grjbxxbsh,@xgbz,@sjly,@klx,@kh,@zjlx,@zjhm,@xm --从游标变量中读取值
WHILE @@FETCH_STATUS=0 --判断FETCH语句是否执行成功
BEGIN
--相关操作
print @yljgdm + "--------" + @grjbxxbsh + "--------" + @xgbz
FETCH NEXT FROM empi_cursor into @yljgdm,@grjbxxbsh,@xgbz,@sjly,@klx,@kh,@zjlx,@zjhm,@xm --读取游标变量中的数据
END
CLOSE empi_cursor --关闭游标
DEALLOCATE empi_cursor; --释放游标
以上是 sqlserver游标使用 的全部内容, 来源链接: utcz.com/z/518213.html