存储过程问题。
本人新手。弄了很久都不知道下面哪里有错
create proc pro_pagination
@talName varchar(200)= 'consume ',--表名
@strGetFields varchar(200)= '* ',--返回的字段
@fldName varchar(255)= 'id ',--排序的字段
@pageSize int =4,---页面尺码
@pageIndex int=1,--所在页面页数
@strWhere varchar(200) --查询条件
as
declare
@strSql varchar(200)
if @pageIndex=1
begin
if @strWhere is not null
set @strSql = "select top "+str(@pageSize)+ " "+@strGetFields+ " from "+@talName+ " where "+@strWhere+ " order by "+fldName+ " "
else
set @strSql= "select top "+str(@pageSize)+ " "+@strGetFields+ " from "+@talName+ " order by "+fldName+ " "
end
else
begin
if @strWhere is not null
set @strSql = "select top "+str(@pageSize)+ " "+@strGetFields+ " from "+@talName+ " where "+@fldName+ " > (select max( "+@fldName+ ") from (select top "+str((@pageIndex-1)*@pageSize)+ " "+@fldName+ " from "+@talName+ " ) as taltemp) order by "+fldName+ " "
else
set @strSql = "select top "+str(@pageSize)+ " "+@strGetFields+ " from "+@talName+ " where "+@fldName+ " > (select max( "+@fldName+ ") from (select top "+str((@pageIndex-1)*@pageSize)+ " "+@fldName+ " from "+@talName+ " ) as taltemp) order by "+fldName+ " "
end
服务器: 消息 1038,级别 15,状态 3,过程 pro_pagination,行 23
不能使用空白的对象或列名。如果必要,请使用一个空格。
服务器: 消息 1038,级别 15,状态 1,过程 pro_pagination,行 25
不能使用空白的对象或列名。如果必要,请使用一个空格。
各位老鸟帮帮忙吧。
------解决方案--------------------create proc pro_pagination
@talName varchar(200)= 'consume ',--表名
@strGetFields varchar(200)= '* ',--返回的字段
@fldName varchar(255)= 'id ',--排序的字段
@pageSize int =4,---页面尺码
@pageIndex int=1,--所在页面页数
@strWhere varchar(200) --查询条件
as
declare
@strSql varchar(200)
if @pageIndex=1
begin
if @strWhere is not null
set @strSql = 'select top '+str(@pageSize)+ ' '+@strGetFields+ ' from '+@talName+ ' where '+@strWhere+ ' order by '+fldName+ ' '
else
set @strSql= 'select top '+str(@pageSize)+ ' '+@strGetFields+ ' from '+@talName+ ' order by '+fldName+ ' '
end
else
begin
if @strWhere is not null
set @strSql = 'select top '+str(@pageSize)+ ' '+@strGetFields+ ' from '+@talName+ ' where '+@fldName+ ' > (select max( '+@fldName+ ') from (select top '+str((@pageIndex-1)*@pageSize)+ ' '+@fldName+ ' from '+@talName+ ' ) as taltemp) order by '+fldName+ ' '
else
set @strSql = 'select top '+str(@pageSize)+ ' '