Paging functionality for Sybase databases

Source: Internet
Author: User
Tags rowcount sybase sybase database

The project needs to use the Sybase database paging function, to do all kinds of methods are not successful, and finally use the following stored procedures to successfully implement the function, record the memo.

CREATE PROCEDUREJsp_query_page@sql varchar( -),@start int,@pageSize int  as  begin      Declare @ipage int     Declare @rcount int      Declare @execsql varchar( -)     Declare @sql1 varchar( -)      Declare @t int,@p int,@n int,@l int     begin         Set @sql1=@sql         Set @n=0         Set @l=0         Set @t=charindex('Select',Lower(@sql))         Set @sql=substring(@sql,@t+7, Char_length (@sql)-7)         Set @n=@n+1         Set @l=@l+7          while(@n!=0)         begin             Set @t=charindex('Select',Lower(@sql))             Set @p=charindex(' from',Lower(@sql))             if((@t<@p) and(@t!=0))                 begin                     Set @sql=substring(@sql,@t+7, Char_length (@sql)-7)                     Set @n=@n+1                     Set @l=@l+6+@t                 End             Else                 begin                     Set @sql=substring(@sql,@p+5, Char_length (@sql)-5)                     Set @n=@n-1                     Set @l=@l+4+@p                 End         End         Set @execsql = substring(@sql1,1,@l-5)+', Sybid=identity () into #temp'+substring(@sql1,@l-4, Char_length (@sql1)-@l+5)         Select @rcount=@start + @pageSize         Set RowCount @rcount          Set @execsql = @execsql || 'SELECT * from #temp where sybid>' || Convert(varchar,@start)|| 'and sybid <=' || Convert(varchar,@rcount)          Print @execsql         Execute(@execsql)          Set RowCount 0      End End

Paging functionality for Sybase databases

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.