-- =============================================
-- Author:		<Dirk Strauss>
-- Create date:	<25 May 2017>
-- Description:	<Add or Update the billing instructions for a property>
-- =============================================
CREATE PROCEDURE sproc_PROP1_BillingInstructions_AddUpdate
	@entityId int,
	@billingInstructions 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_BillingInstructions]
		 SET [billingInstructions] = @billingInstructions		    
	    WHERE [entityId] = @entityId;
	    
	IF @@ROWCOUNT = 0
	BEGIN
	-- If nothing updated, try insert
	   INSERT INTO [dbo].[prop1_BillingInstructions]
			([entityId]
			,[billingInstructions])
	    VALUES
			(@entityId
			,@billingInstructions)
	END
		
	COMMIT TRANSACTION;
END

