I use a table-valued function as a parametered view. Almost everything works, except the 'order by' part.I altered the original function into this short one.
The function:
ALTER FUNCTION [dbo].[fn_Get_NormalOrders]
(
@minimalLevel int,
@recordStart int,
@recordsEnd int,
@orderBy varchar(30)
)
RETURNS TABLE
AS
RETURN
(
select *
from
(
select
ROW_NUMBER() over (order by @orderBy) as row
,d.nameModel
,t.idToner
from toner t
inner join vwWebDevice d on d.idDevice = t.idDevice
and d.statusDevice not like '%stale%'
and isnull(d.deleted,0) = 0
inner join groups g on g.idGroup = d.idGroup
where
t.currentLevel <= @minimalLevel
) as x
where x.row between @recordStart and @recordsEnd
)
I found a solution by making a varchar of this query and execute this, but how do i return te result? When i use it as it is now, than the result is always the same.