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

CREATE PROCEDURE dbo.sp_UpdateOrarendiOraVisszamenolegesen
   @oldCsengetesiRendOraId int
  ,@newCsengetesiRendOraId int
AS
BEGIN

	DECLARE @Oraszam int; DECLARE @Kezdete datetime; DECLARE @Vege datetime;
	SELECT @Oraszam = C_ORASZAM, @Kezdete = C_KEZDETE, @Vege = C_VEGE FROM T_CSENGETESIRENDORA WHERE ID = @newCsengetesiRendOraId
	
	UPDATE oo
	SET
		C_ORAKEZDETE = @Vege
		,C_ORAVEGE = @Kezdete
		,C_ORASZAM = @Oraszam
	FROM T_ORARENDIORA oo
	WHERE
		oo.C_CSENGETESIRENDORAID = @oldCsengetesiRendOraId

END
GO