IF OBJECT_ID('dbo.sp_UpdateOrarendiOraToroltCsengetesiRend') IS NOT NULL BEGIN
  DROP PROCEDURE dbo.sp_UpdateOrarendiOraToroltCsengetesiRend
END
GO

CREATE PROCEDURE dbo.sp_UpdateOrarendiOraToroltCsengetesiRend
   @toroltCsengetesiRendId int
  ,@intezmenyId int
  ,@tanevId int
AS
BEGIN

	DECLARE @aktivCsengetesiRendId int =
		(SELECT csro.ID FROM T_CSENGETESIREND_OSSZES csro WHERE csro.C_AKTIV = 'T' AND csro.C_TANEVID = @tanevId AND csro.C_INTEZMENYID = @intezmenyId)
	
	
	UPDATE oo
	SET
		C_CSENGETESIRENDID = @aktivCsengetesiRendId
	FROM T_ORARENDIORA oo
	WHERE
		oo.C_CSENGETESIRENDID = @toroltCsengetesiRendId

END
GO