
CREATE PROCEDURE [dbo].[sp_GetSurfaceQueryItemData]
	@SurfaceID int,
	@SurfaceItemID int
	
AS
BEGIN
	--For testing:
	--DECLARE
	--@SurfaceID int = 3046,
	--@StartIndex int = 0,
	--@MaxRows int = 20,
	--@OrderBy Varchar(500),
	--@Search Varchar(500),
	--@userLink int = 0,
	--@Filter Varchar(1000) = '',
	--@UserId INT = 219 --Jas Admin Id

	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

		DECLARE @QueryTableName varchar(300) = ''

		SET @QueryTableName = 'qt_' + (SELECT name from pal_Surface Where recId = @SurfaceID)
		
		
		DECLARE @query  AS VARCHAR(MAX)		

				
		set @query = N' 
				SELECT  * FROM 	' + @QueryTableName + '							
				WHERE itemID = ' + CAST(@SurfaceItemID as varchar(800))							
														
				
		--print @query;
		--PRINT @query2;
		exec (@query)
END







