中间有两个参数:@pagenum int,@itemid int,
@itemid :是表(test)中的类型字段。

解决方案 »

  1.   

    --有位打吓说了啊。是不是这个问题??
    if @row_num='0' =========》 if @row_num=0
    begin
      print '没有记录'
    end
      

  2.   

    楼上说得不对,我测试了下,INT类型可以字符型兼容,请在查询分析器里运行下面测试语句:
    declare @i int
    set @i=0
    if @i='0' print 'ok' else print 'false'
      

  3.   

    CREATE proc page
    @pagenum int,
    @itemid int
    as
    SET NOCOUNT ON /*-----这一句很重要哦:)),不然它只会认 insert #change......这个数据集:))*/
    declare @sql nvarchar(500) --声明动态sql执行语句
    declare @pagecount int --当前页数--取得当前数据库的记录总数
    declare @row_num int 
    begin 
    select @row_num=count(*) from test t where t.itemid=@itemid 
    --创建临时表,作为数据过滤
    create table #change (itemid int)--判断当前页数
    if @row_num>3 --大于页面显示记录数,则分页
    begin
    set @row_num=@pagenum*3
    if @row_num=3
        select top 3 * from test t where t.itemid=@itemid order by id desc
    else
    begin
    set @row_num=(@pagenum-1)*3
    set @pagecount=@row_num
    set @sql='insert #change (itemid) select top '+cast(@pagecount as char(100))+' itemid from test where itemid not in (select itemid from #change)'
    exec sp_executesql @sql
    select top 3 * from test where itemid not in (select itemid from #change)
    end
    end
    else --只现实全部的数据
    select * from test t where t.itemid=@itemid order by id desc
    end
    GO
    还是只能选出第一爷的数据,不能选出第二爷的数据啊,语法没有错误,是逻辑上的错误。