Saturday 11 September 2021

Loop through table in mssql

SET NOCOUNT ON

 

DECLARE @ParcelCode nvarchar(100)

 

DECLARE load_cursor CURSOR FOR

    SELECT [ParcelCode]

    FROM dbo.[Info_parcels05]

 

OPEN load_cursor

FETCH NEXT FROM load_cursor INTO @ParcelCode

 

WHILE @@FETCH_STATUS = 0

BEGIN

    BEGIN

              update [dbo].[Info_parcels05]

                           set PriceByHumen=(SELECT FLOOR(RAND()*(1000000))),PriceByMachine=(SELECT FLOOR(RAND()*(1000000)))

                           where ParcelCode=@ParcelCode

         

    END 

    FETCH NEXT FROM load_cursor INTO @ParcelCode

       print @ParcelCode

END

 

CLOSE load_cursor

DEALLOCATE load_cursor

GO


No comments:

Post a Comment