Below a partial of the existing stored procedure before my changes CREATE PROCEDURE [dbo].[GetSelectedStoreDetail] @StoreID uniqueidentifier, @InvoiceList varchar(650) AS BEGIN -- Declare a table variable and use a UDF to load the variable with invoice numbers from @InvoiceList. DECLARE @InvoiceTable table(ItemInt int NOT NULL); INSERT @InvoiceTable SELECT ItemInt FROM dbo.function_split_To_Int(@InvoiceList, ','); SELECT [InvID] ,[StoreID] ,[InvoiceNumber] ,[InvoiceDate] . . FROM InvoiceHeaderView WHERE StoreID = @StoreID And InvoiceNumber IN (SELECT ItemInt FROM @InvoiceTable) ORDER BY InvoiceNumber; END Below is what I have tried. CREATE PROCEDURE [dbo].[GetSelectedStoreDetail] @StoreID uniqueidentifier, @InvoiceList varchar(650) @SortBy VarChar(100) AS BEGIN DECLARE @SelectStatement nvarchar(4000) -- Declare a table variable and use a UDF to load the variable with invoice numbers from @InvoiceList. DECLARE @InvoiceTable table(ItemInt int NOT NULL); INSERT @InvoiceTable SELECT ItemInt FROM dbo.function_split_To_Int(@InvoiceList, ','); SET @SelectStatement = 'SELECT [InvID] ,[StoreID] ,[InvoiceNumber] ,[InvoiceDate] . . FROM EDIHeaderAddrView WHERE MemberID = ' + @MemberID + ' And ASWDocNum IN (SELECT ItemInt FROM ' + @InvoiceTable + ') ' + ' ORDER BY ' + @sortBy; exec sp_executesql @SelectStatement; END I also tried the following Declare @CreateTableStatement nvarchar(4000) Set @CreateTableStatement = 'DECLARE @InvoiceTable table(ItemInt int NOT NULL);' exec sp_executesql @CreateTableStatement, N'@Result varchar(max) out', @InvTable out Declare @PopulateTableStatement nvarchar(4000) set @PopulateTableStatement = 'INSERT ' + @InvTable + 'SELECT ItemInt FROM dbo.function_split_To_Int(@InvoiceList,' + ''''',''''' + ')'; exec sp_executesql @PopulateTableStatement, N'@Result varchar(max) out', @InvoiceTable out I am still getting the same error, must declare the scalar variable @InvTable