Showing posts with label Code to User Loop In sql Server. Show all posts
Showing posts with label Code to User Loop In sql Server. Show all posts

Monday, February 1, 2010

Updating a set of rows in Sql Server : How to use While loop in Sql Server

Declare @PubId int
set @PubId = 1046

Declare @NewsId int
set @NewsId = 7026


Begin Tran T2
WHILE (@NewsId <= 7125)
BEGIN


update MstReports
set ReportCode = 'Ovum' + CONVERT(VARCHAR(10),@PubId)
where NewsId = @NewsId


print @newsid

SET @NewsId = @NewsId + 1
SET @PubId = @PubId + 1
IF @NewsId = 7126
BREAK;
END

rollback

or

commit