﻿SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

IF OBJECT_ID('[dbo].[sp_SetBeiratkozasVeglegesites]') IS NOT NULL 
BEGIN
  DROP PROCEDURE [dbo].[sp_SetBeiratkozasVeglegesites]
END
GO

CREATE PROCEDURE [dbo].[sp_SetBeiratkozasVeglegesites]
	-- Add the parameters for the stored procedure here
	 @pIsVeglegesites		BIT 
	,@pUserId				INT
AS
BEGIN

	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;	

	DECLARE @currentDateTime DATETIME 
	SET @currentDateTime = (SELECT GETDATE())

	IF (@pIsVeglegesites = 1)
		BEGIN
			UPDATE 
				[T_INTEZMENYADATSZOLGALTATAS] 
			SET 
				 C_VEGLEGESBEIRATKOZAS =			'T'

				,SERIAL =							SERIAL + 1
				,LASTCHANGED =						@currentDateTime
				,MODIFIER =							@pUserId;
		END
	ELSE
		BEGIN
			UPDATE 
				[T_INTEZMENYADATSZOLGALTATAS] 
			SET 
				 C_VEGLEGESBEIRATKOZAS =			'F'

				,SERIAL =							SERIAL + 1
				,LASTCHANGED =						@currentDateTime
				,MODIFIER =							@pUserId;
		END

END

