-- =============================================
-- Author:		<Dirk Strauss>
-- Create date:	<14 June 2017>
-- Description:	<Add or Update the lookup details for a property>
-- =============================================
CREATE PROCEDURE [dbo].[sproc_PROP1_PropertyLookupDetails_AddUpdate]
	@propertyID INT,
	@propertyName NVARCHAR(MAX),
	@propertyLookupDetails NVARCHAR(MAX)
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;
     SET TRANSACTION ISOLATION LEVEL SERIALIZABLE;
	BEGIN TRANSACTION;	   
	-- Try update
	   UPDATE [dbo].[prop1_PropertyLookupDetails]
		 SET [propertyLookupDetails] = @propertyLookupDetails
			, [propertyName] = @propertyName	    
	    WHERE [propertyID] = @propertyID;
	    
	IF @@ROWCOUNT = 0
	BEGIN
	-- If nothing updated, try insert
	   INSERT INTO [dbo].[prop1_PropertyLookupDetails]
			([propertyID]
			,[propertyName]
			,[propertyLookupDetails])
	    VALUES
			(@propertyID
			,@propertyName
			,@propertyLookupDetails)
	END
		
	COMMIT TRANSACTION;
END