--查询数据
select
Invest.UserId,
BorrowReturn.RealReturnTime,
Borrow.InvestType,
case Borrow.InvestType
when 0 then '成功000,请注意查收'
when 1 then '成功111,请注意查收'
when 2 then '成功222,请注意查收'
when 4 then '成功444,请注意查收'
else ''
end
as SiteMessageContent ,
(BorrowReturnDetail.CaptionMoney+BorrowReturnDetail.InterestMoney+BorrowReturnDetail.SubsidyInterest-BorrowReturnDetail.ReduceManageFee) as BorrowReturnMoney
into #t --放入临时表中
from BorrowReturn
left join BorrowReturnDetail on BorrowReturn.Id=BorrowReturnDetail.BorrowReturnId
left join Borrow on Borrow.Id=BorrowReturn.BorrowId
left join Invest on Invest.Id=BorrowReturnDetail.InvestId
where BorrowReturn.IsDeleted=0 and BorrowReturn.IsSuccess=1 and BorrowReturnDetail.IsDeleted=0
declare @UserId int --临时变量,用来保存游标值
declare @SiteMessageContent varchar(500)
declare @RealReturnTime datetime
declare @BorrowReturnMoney decimal(18,2)
DECLARE @error int
SQL 利用游标循环添加数据
最新推荐文章于 2021-07-21 13:24:04 发布
该博客介绍了如何使用SQL的游标进行数据处理,包括将查询结果存入临时表,然后通过游标循环遍历每一项,向SiteMessage和CapitalFlow表中插入数据,实现站内信和资金流水的记录更新。整个过程使用了事务处理,确保数据的一致性。

最低0.47元/天 解锁文章
8104

被折叠的 条评论
为什么被折叠?



