CREATE PROC [dbo].[sp_UpdateSurfaceData]
(
	@surfaceId INT
)
AS

SET NOCOUNT ON

DECLARE @linkedSurfaceId INT
DECLARE @linkedSurfaces TABLE (surfaceLinkId INT)

INSERT INTO @linkedSurfaces
SELECT surfaceId FROM pal_SurfaceLink WHERE @surfaceId = linkedSurfaceId

WHILE (SELECT COUNT(1) FROM @linkedSurfaces) > 0
BEGIN
	SELECT @linkedSurfaceId = surfaceLinkId FROM @linkedSurfaces				
	EXEC sp_SetSurfaceDataFromLinks @linkedSurfaceId 
	DELETE FROM @linkedSurfaces WHERE surfaceLinkId = @linkedSurfaceId
END

EXEC sp_SetLabelValues @SurfaceID
