IF EXISTS (SELECT name FROM sysobjects WHERE  name = 'sp_pxp_lock_ccda_request' AND type = 'P')
   DROP PROCEDURE sp_pxp_lock_ccda_request
GO
CREATE PROCEDURE [dbo].[sp_pxp_lock_ccda_request]
	
	 @pi_id			 uniqueidentifier,
	 @pi_request_id  uniqueidentifier,
	 @pi_consumer_id int,
	 @pi_ccda_type   tinyint,
	 @pi_create_timestamp datetime,
	 @pi_created_by int,
	 @pi_modify_timestamp datetime,
	 @pi_modified_by int,
	 @pi_unix_milliseconds bigint
	
AS
BEGIN

IF NOT EXISTS (Select request_id from pxp_ccda_requests_locks where request_id = @pi_request_id)
	INSERT INTO [dbo].[pxp_ccda_requests_locks]
						(
						     [id]
							,[request_id]							
							,[consumer_id]
							,[ccda_type]
							,[create_timestamp]
							,[created_by]
							,[modify_timestamp]
							,[modified_by]
							,[unix_milliseconds]
						)
						VALUES
						(
						     @pi_id
							,@pi_request_id							
							,@pi_consumer_id
							,@pi_ccda_type
							,@pi_create_timestamp
							,@pi_created_by
							,@pi_modify_timestamp
							,@pi_modified_by
							,@pi_unix_milliseconds													
						)

END
GO