text: USE [Monopoly]
  GO
  
  /****** Object:  UserDefinedFunction [Game].[svfEvaluatePropertyCost]    Script Date: 2/19/2022 10:29:12 AM ******/
  SET ANSI_NULLS ON
  GO
  
  SET QUOTED_IDENTIFIER ON
  GO
  
  CREATE FUNCTION [Game].[svfEvaluatePropertyCost] (
  	@player int,
  	@property varchar(50)
  )
  RETURNS INT
  AS
  BEGIN
  	DECLARE @cost INT;
  
  	IF @property IN (SELECT [property] FROM [Player].[PropertiesOwned])
  		BEGIN
  			IF @player = (SELECT [player] FROM [Player].[PropertiesOwned] WHERE [property] = @property)
  				-- Player owns property, no immediate cost
  				SET @cost = 0;
  			ELSE
  				-- Another player owns property, return rent amount
  				SELECT @cost = [rent] FROM [Game].[vwPropertyRent] WHERE [property] = @property;
  		END
  	ELSE
  		-- Property not currently owned by any player, return building cost
  		SELECT @cost = [building_cost] FROM [Game].[Properties] WHERE [name] = @property;
  
  	RETURN @cost;
  END
  GO
  
  
  