Question : tweaking my stored proc

I am working on a stored procedure that I want to return values based on parameters.  It works with the exception that the desired order is being ignored.  

Can someone point out my error in this?

set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go






ALTER procedure [dbo].[getNumListPagedOrder]

(

            @pageIndex int,

            @maximumRows int,

                  @sortorder nvarchar(20)

)

as

(

select [dwg no#], [drawing title], pk, rowid

from (

select      [dwg no#] ,
            [drawing title],  
            pk,
            row_number() over (order by @sortorder) as rowid from numlist ) as NumListNumbered

where rowid > ((@pageIndex-1)*@maximumRows) and rowid < ( ( @pageIndex * @maximumRows )+1 )

)


Answer : tweaking my stored proc

Try this:

1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
ALTER PROCEDURE [dbo].[getNumListPagedOrder]
@pageIndex int,
@maximumRows int,
@sortorder nvarchar(20)
AS
 
DECLARE @Query VARCHAR(1000)
DECLARE @CalcValue1 INT
DECLARE @CalcValue2 INT
 
SET @CalcValue1 = (@pageIndex-1)*@maximumRows)
SET @CalcValue2 = (@pageIndex * @maximumRows )+1
 
SET @Query = '
SELECT [dwg no#], [drawing title], pk, rowid
FROM (
SELECT [dwg no#] , [drawing title], pk,
       row_number() over (order by ' + @sortorder + ') as rowid from numlist ) as NumListNumbered
where rowid > (' + Cast(CalcValue1 AS VARCHAR(20)) + ') and rowid < (' + CAST(@CalcValue2 AS VARCHAR(20)) + ')'
 
EXECUTE(@Query)
 
GO
Random Solutions  
 
programming4us programming4us