create procedure procPage @startIndex int,@endIndex int,@sort varchar(50)='asc'
as
with pageTamp as(
select row_number() over(order by id @sort) as row,* from dbo.WZ_YouQing)
select * from pagetamp where row between @startIndex and @endIndex
消息 102,级别 15,状态 1,过程 procPage,第 4 行
'@sort' 附近有语法错误。
- 上面这样写为什么错误呢?
只有下面这样写吗,有没有更简单的方法哦?
Code
create procedure procPage @startIndex int,@endIndex int,@sort varchar(50)='asc'
as
if @sort='asc'
begin
with pageTamp as(
select row_number() over(order by id asc) as row,* from dbo.WZ_YouQing)
select * from pagetamp where row between @startIndex and @endIndex
end
else
begin
with pageTamp as(
select row_number() over(order by id desc) as row,* from dbo.WZ_YouQing)
select * from pagetamp where row between @startIndex and @endIndex
end