i have a stored procedure that making paging and i need it to make sorting the CREATE PROCEDURE [dbo].[Category_pager]( @startRowIndex int, @maximumRows int, @sortedBy varchar(50), @TotalRecords INT out )AS--Create a table variableDECLARE @TempItems TABLE( IndexID int IDENTITY, catID int PRIMARY KEY (IndexID)) INSERT INTO @TempItems (catID) SELECT [Category].id FROM [Category] select @TotalRecords= @@ROWCOUNT---Now, return the set of paged recordsSELECT c.id, c.categoryNameFROM @TempItems t INNER JOIN Category c ON c.id = t.catIDWHERE IndexID BETWEEN @startRowIndex AND (@startRowIndex + @maximumRows) - 1GO
i want to add the @sortedBy to the select statement in the red paragraph so i did thatDeclare @sql nvarchar(4000)set @sql =' INSERT INTO @TempItems (catID) SELECT [Category].id FROM [Category] ORDER BY '+@sortedBy
it gives me errori think that error because i can't use table variable in exec insert any help please 