-- =============================================
-- Author:		Jas Rademeyer
-- Create date: 2017-06-08
-- Description:	Call SetItemLabelValues proc after any change to the item table
-- =============================================
CREATE TRIGGER Trigger_SurfaceItem
   ON  dbo.pal_SurfaceItem 
   AFTER INSERT,UPDATE
AS 
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

    -- Insert statements for trigger here
	DECLARE @itemId INT
			,@surfaceId INT

	SELECT	@itemId = I.recId
			,@surfaceId = I.surfaceId
	FROM	inserted I

	IF NOT EXISTS (SELECT 1 FROM pal_JobProcsLocal
					WHERE	procName = 'sp_SetItemLabelValues'
							AND procParams = CAST(@itemId AS VARCHAR(20))+','+CAST(@surfaceId AS VARCHAR(20))
							AND todo = 1)
	INSERT INTO pal_JobProcsLocal SELECT 'sp_SetItemLabelValues',CAST(@itemId AS VARCHAR(20))+','+CAST(@surfaceId AS VARCHAR(20)),1
END