sql里循环(sql里面写循环)

sql里循环(sql里面写循环)select orderNum userName MoneyTotal into t from FOrders po DECLARE n int error int set n 1 set error 0 BEGIN TRAN 申明事务 declare tmp varchar 50 userN

大家好,我是讯享网,很高兴认识大家。



select orderNum,userName,MoneyTotal into #t from FOrders po DECLARE @n int,@error int set @n=1  set @error=0   BEGIN TRAN 申明事务     declare @tmp varchar(50),@userN varchar(50) 临时变量,用来保存游标值     declare y_curr cursor for 申明游标 为orderNum,userName     select orderNum,userName from FOrders where Orderid<50     open y_curr     fetch next from y_curr into @tmp,@userN     while @@fetch_status = 0       BEGIN         select isnull(sum(MoneyTotal),0),orderNum from #t where username=@userN          set @n=@n+1         set @error=@error+@@error记录每次运行sql后 是否正确 0正确         fetch next from y_curr into @tmp,@userN       END     IF @error=0     BEGIN   commit tran 提交 END ELSE   BEGIN     ROLLBACK TRAN 回滚   END close y_curr deallocate y_curr DROP TABLE #t

讯享网


讯享网


小讯
上一篇 2025-04-28 22:00
下一篇 2025-06-02 11:55

相关推荐

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容,请联系我们,一经查实,本站将立刻删除。
如需转载请保留出处:https://51itzy.com/kjqy/156484.html