Hello.
I need some help. I need to convert this code with cursors to set-based operations. I can't understand how I can make the set-based code do the same as with cursors.
DECLARE Cursor static local FOR
SELECT Cid,Abrev FROM EntityType
OPEN Cur
FETCH NEXT FROM Cur INTO @entityType, @entityTypeAbrev
WHILE @@FETCH_STATUS = 0
BEGIN
SET @CurEnt = Cursor static local FOR
SELECT did FROM Entity where EntityTypeCid=@entityType
OPEN @CurEnt
FETCH NEXT FROM @CurEnt INTO @entityId
	WHILE @@FETCH_STATUS = 0
	BEGIN
		SET @RandNumber= FLOOR(RAND()*(28-1)+1);
	
		select @entityNumber=EntityNumber from Entity 
		where did=@entityId
		--print @entityNumber
		SET @FullName= @entityTypeAbrev + ' ' + cast(@entityNumber as nvarchar)
		SET @ShortName = @FullName 
		/* 
		* ENTITY*/
	
		UPDATE entity set fullname=@FullName, ShortName=@ShortName where did=@entityId
	
		UPDATE Agenda set EntityName= @FullName where EntityDid=@entityId 
--Intervetions
SET @CurIntervs = Cursor static local FOR
select did, CredOperIntervType from CredOperInterv where EntityDid=@entityId
OPEN @CurIntervs
FETCH NEXT FROM @CurIntervs INTO @credOperIntervDid, @credOperIntervTypeId
WHILE @@FETCH_STATUS = 0
BEGIN
Thanks in advance
Paulo Dias