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

SELECT	@returnVal = SUM(CASE F.surfaceFieldTypeId 
			WHEN 4
			THEN D.surfaceFieldValueNum
			WHEN 5
			THEN D.surfaceFieldValueDecimal
			END)
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 0 < CASE F.surfaceFieldTypeId 
					WHEN 4
					THEN D.surfaceFieldValueNum
					WHEN 5
					THEN D.surfaceFieldValueDecimal
					END

RETURN	@returnVal

END