set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
GO
ALTER procedure [dbo].[sys_getPagerData]
@pageSize int,
@pageIndex int,
@fields nvarchar(100),
@Chart nvarchar(50),
@recordCount int output,
@pageCount int output
AS
declare @Sql nvarchar(300)
declare @count1 int;
select @recordcount=count(id) from "@Chart"
select @pagecount=floor(@recordCount/@pageSize);
if(@recordCount%@pageSize!=0)set @pagecount=@pageCount+1
set @sql='select top '+convert(nvarchar,@pageSize)+' '+
@fields+' from '+@Chart+' where(ID not in(select top '+
convert(nvarchar,@recordCount-@pageSize*@pageIndex)+' id from '+@Chart+
' order by id desc))'
execute(@Sql)
创建没问题但是执行后就提示: 必须声明表变量 "@Chart"。