# 一个分页存储过程中的逻辑问题！！！！急

0

`Codealter proc UserInfos_SelectAllPaged@pageCount int,   --每页显示的条数@pageNow int,     --当前页数@tableName varchar(50),  --表名@primaryName varchar(50),  --表主键的名字@condition varchar(500),   --搜索条件@Count int output        --返回总记录数asdeclare @sql nvarchar(2000)declare @sqlcount varchar(500)declare @strFilters nvarchar(500)set @strFilters = @conditiondeclare @countTemp int if(@condition = '')    --无条件搜索,默认为空begin  set @sql = 'select top ' + cast(@pageCount as varchar) + ' * from ' + @tableName+ ' where ' + @primaryName + ' not in (select top ' + cast(@pageCount*(@pageNow-1) as varchar) + ' ' + @primaryName + ' from '+ @tableName+')'exec(@sql)endelsebegin  set @sql = 'select top ' + cast(@pageCount as varchar) + ' * from ' + @tableName+ ' where ' + @primaryName + ' not in (select top ' + cast(@pageCount*(@pageNow-1) as varchar) + ' ' + @primaryName + ' from '+ @tableName+')' + ' and ' + @strFiltersexec(@sql)endSET @sql=N'SELECT @countTemp=COUNT(*)' +N' FROM '+@tableName EXEC sp_executesql @sql,N'@countTemp int OUTPUT',@countTemp OUTPUT set @Count = @countTemp`

exec UserInfos_SelectAllPaged 2,1,'userinfo','pkid','pkid > 1',@dd output

0
`  set @sql = 'select top ' + cast(@pageCount as varchar) + ' * from ' + @tableName+ ' where ' + @primaryName + ' not in (select top ' + cast(@pageCount*(@pageNow-1) as varchar) + ' ' + @primaryName + ' from '+ @tableName+')' + ' and ' + @strFilters你的过滤条件有问题，修改成  set @sql = 'select top ' + cast(@pageCount as varchar) + ' * from ' + @tableName+ ' where ' + @primaryName + ' not in (select top ' + cast(@pageCount*(@pageNow-1) as varchar) + ' ' + @primaryName + ' from '+ @tableName + 'WHERE' + @strFilters +')' +  ' and ' + @strFilters`

persialee | 老鸟四级 |园豆：3217 | 2009-11-20 12:58

0

您需要登录以后才能回答，未注册用户请先注册