CREATE PROCEDURE [dbo].[sp_DeleteSurfaceItemQueryTable]
	@SurfaceID int,
	@ItemID int
AS
BEGIN
	
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;
	DECLARE @IsLinkedSurface BIT = 0;
	DECLARE @QueryTableName varchar(300) = ''

		SET @QueryTableName = 'qt_' + (SELECT name from pal_Surface Where recId = @SurfaceID)

		DECLARE @DeleteQuery varchar(800)
		SET @DeleteQuery = 'Delete FROM ' + @QueryTableName + ' WHERE itemID = ' + CAST(@ItemID As varchar) + ' '
		EXEC(@DeleteQuery)
			
END







GO


