DROP PROCEDURE IF EXISTS uspUpdateNemKotottMunkaIdoByGroupId
GO

CREATE PROCEDURE uspUpdateNemKotottMunkaIdoByGroupId
   @pTanevId int
  ,@pIdoszakKezdete datetime
  ,@pIdoszakVege datetime
  ,@pGroupId uniqueidentifier
  ,@pNewGroupId uniqueidentifier
  ,@pTorvenyikategoria int
  ,@pMegjegyzes nvarchar(MAX)
  ,@pUserId int
AS
BEGIN
  SET NOCOUNT ON;

  UPDATE nkm SET
   nkm.C_TEVEKENYSEGTIPUSA = @pTorvenyikategoria
  ,nkm.C_MEGJEGYZES = @pMegjegyzes
  ,nkm.C_KEZDETE = CAST(CAST(nkm.C_KEZDETE as date) as datetime) + CAST(CAST(@pIdoszakKezdete as time) as datetime)
  ,nkm.C_VEGE = CAST(CAST(nkm.C_VEGE as date) as datetime) + CAST(CAST(@pIdoszakVege as time) as datetime)
  ,nkm.LASTCHANGED = GETDATE()
  ,nkm.SERIAL = nkm.SERIAL+1
  ,nkm.MODIFIER = @pUserId
  ,nkm.C_GROUPID = @pNewGroupId
  FROM T_NEMKOTOTTMUNKAIDO_OSSZES nkm 
  WHERE nkm.C_GROUPID = @pGroupId
    AND CAST(@pIdoszakKezdete as date) <= CAST(nkm.C_KEZDETE as date)
    AND CAST(@pIdoszakVege as date) >= CAST(nkm.C_VEGE as date)
    AND nkm.TOROLT = 'F' AND C_MEGTARTOTT = 'F'
END
GO