Wednesday, September 22, 2010

[MSSQL] Cursor and While loop sample

Below sample usage of Cursor and While loop

--fixing missing document reviewer
declare @siteno varchar(10), @docid as bigint, @sitever as int
DECLARE c1 CURSOR READ_ONLY
FOR
select (select site_no from codsite where site_id=wft.site_id) siteno, docid, siteversion from wftransaction wft
where site_id in (select site_id from codsite where site_no='SKY078D') and tsk_id=5 and enddatetime is null
OPEN c1
FETCH NEXT FROM c1
INTO @siteno,@docid,@sitever
WHILE @@FETCH_STATUS = 0
BEGIN
PRINT convert(varchar(max),@siteno)+' '+convert(varchar(max),@docid)+' '+convert(varchar(max),@sitever)
exec refreshingWFReview @siteno,@docid,@sitever
FETCH NEXT FROM c1
INTO @siteno,@docid,@sitever
END
CLOSE c1
DEALLOCATE c1

No comments:

Post a Comment