SQL中游标的用法

Posted xiaoyichong

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了SQL中游标的用法相关的知识,希望对你有一定的参考价值。


if object_id(‘##tmp1‘) is not null
drop table #tmp1
select staffno, paydate
into #tmp1
from dbo.OSS_ClockingDetail
where paydate>getdate()-50 and ProcessInd=‘P‘ and ActionBy=‘D‘ and paymonth is null
group by staffno,paydate
declare @staffno varchar(6)
declare @paydate datetime
declare cur cursor for select staffno, paydate
from #tmp1
open cur
fetch next from cur into @staffno,@paydate
WHILE (@@FETCH_STATUS = 0)
begin
update dbo.OSS_Rawclocking set intime=‘‘,outtime=‘‘,payhour=0,offind=0 where [email protected] and [email protected]
update dbo.OSS_ClockingDetail set ProcessInd=‘U‘ where [email protected] and ProcessInd=‘P‘ and ActionBy=‘D‘ and paymonth is null and [email protected]
fetch next from cur into @staffno,@paydate
end
close cur
DEALLOCATE cur

以上是关于SQL中游标的用法的主要内容,如果未能解决你的问题,请参考以下文章

SQL用法三(游标和Fetch)

sql server 游标的简单用法

SQL server 游标用法

plsql--游标用法

游标SQL Cursor 基本用法

oracle cursor 用法总结