存储过程,怎样写。返回一个分页,页数。
 在SQL 里,怎样用上这句话  
(RecordTotal % pagesize) == 0 ? (RecordTotal / pagesize) : (RecordTotal / pagesize + 1); sql 句语.能用上if 等语句吗。 在那里有这些教程的。我找了很久都没打到。最好是视频教程。thx~

解决方案 »

  1.   

    (select count(*) from 表)/每页条数
      

  2.   

    http://topic.csdn.net/u/20091013/13/1ba85d9b-ef2e-41d1-9fd5-11218015264c.html
      

  3.   

    恩存储过程中可以使用if
    但是如果只是简单的判断case..when就可以了
    select case when firstname='admin' then 'administrator' end as firstName from testtable
      

  4.   


    Declare @myCount int 
    Declare @RecordTotal int 
    Declare @pageSize int
    set @RecordTotal=1234
    set @pageSize=100
    set @myCount=Round(@RecordTotal/@pageSize,0,1)
    if(@myCount=0)
    print '正好分完,共'+cast(@myCount as nvarchar(10))+'页'
    else
    begin
    set @mycount=@mycount+1
    print '共'+cast(@myCount as nvarchar(10))+'页,其中有一页不足'+cast(@pageSize as nvarchar(10))
    end
      

  5.   

    (RecordTotal % pagesize) == 0 ? (RecordTotal / pagesize) : (RecordTotal / pagesize + 1); 
    sql语句或者存储过程里,可以用if判断,也可以case when..
    视频教程就不知道了,一般都是看书比较多,或者看代码
    declare @recordtotal int,@pagesize intif @recordtotal % @pagesize = 0 
    BEGIN
       return @RecordTotal / @pagesize
    END
    else
    BEGIN
       return @RecordTotal / @pagesize +1
    END
      

  6.   

    ceiling返回大于或等于该数的最小整数
    Floor返回小于或等于该数字的最大整数
      

  7.   

    使用 IF...ELSE
    IF 语句用于条件的测试。结果流的控制取决于是否指定了可选的 ELSE 语句: 指定 IF 而无 ELSE 
    IF 语句取值为 TRUE 时,执行 IF 语句后的语句或语句块。IF 语句取值为 FALSE 时,跳过 IF 语句后的语句或语句块。指定 IF 并有 ELSE 
    IF 语句取值为 TRUE 时,执行 IF 语句后的语句或语句块。然后控制跳到 ELSE 语句后的语句或语句块之后的点。IF 语句取值为 FALSE 时,跳过 IF 语句后的语句或语句块,而执行 ELSE 语句后的语句或语句块。例如,如果存储过程一直保存事务中 @@ERROR 返回的错误代码,则在过程结尾可能有与下面语句相似的 IF 语句:IF (@ErrorSaveVariable <> 0)
    BEGIN
       PRINT 'Errors encountered, rolling back.'
       PRINT 'Last error encountered: ' +
          CAST(@ErrorSaveVariable AS VARCHAR(10))
       ROLLBACK
    END
    ELSE
    BEGIN
       PRINT 'No Errors encountered, committing.'
       COMMIT
    END
    RETURN @ErrorSaveVariable
      

  8.   

    CREATE procedure pro_messageRecord
    @count int output,
    @pageCount int output
    as
    set @count=(select count(*) from leaveMessage)
    declare @pageSize int
    set @pageSize=4
    if(@count%@pageSize=0)
    set @pageCount=@count/@pageSize
    else
    set @pageCount=@count/@pageSize+1
    select count(*) from leaveMessage