CREATE FUNCTION [dbo].[fn_GetSurfaceFieldAggregateDistinctionCount]
( 
	@surfaceItemId INT
	,@actionValue VARCHAR(255)
)
RETURNS INT
AS
BEGIN
DECLARE @returnVal INT

SELECT	@returnVal = COUNT(1)
FROM	pal_SurfaceField F
		JOIN pal_SurfaceFieldData D
			ON D.surfaceFieldID = F.recId
WHERE	D.surfaceItemId = @surfaceItemId
		AND F.recId IN (SELECT splitdata FROM SplitString(@actionValue,'|'))
		AND 79 < CASE F.surfaceFieldTypeId 
					WHEN 4
					THEN D.surfaceFieldValueNum
					WHEN 5
					THEN D.surfaceFieldValueDecimal
					END
RETURN	@returnVal

END