declare @user_condition varchar(500)
declare @user_sort varchar(20)
declare @user_rank varchar(4)
declare @page_size real
declare @page_order int
declare @sqlquery varchar(1000)
set @page_size = 10
set @page_order = 1
set @user_sort = 'digitaltion_id'
set @user_rank = 'desc'
if (@page_order > 0)
if (@user_rank = 'asc')
begin
set @sqlquery = 'select top '+ str(@page_size) +' digitaltion_id from [digitalart_digitaltion] where (digitaltion_id > (select max(digitaltion_id) from (select top '+ str(@page_order * @page_size) +' digitaltion_id from [digitalart_digitaltion] order by '+ @user_sort +' asc) as teamtable)) order by '+ @user_sort +' asc'
endelse
begin
set @sqlquery = 'select top '+ str(@page_size) +' digitaltion_id from [digitalart_digitaltion] where (digitaltion_id < (select min(digitaltion_id) from (select top '+ str(@page_order * @page_size) +' digitaltion_id from [digitalart_digitaltion] order by '+ @user_sort +' desc) as teamtable)) order by '+ @user_sort +' desc'
endelse
if (@user_rank = 'asc')
begin
set @sqlquery = 'select top '+ str(@page_size) +' digitaltion_id from [digitalart_digitaltion] order by '+ @user_sort +' asc'
endelse
begin
set @sqlquery = 'select top '+ str(@page_size) +' digitaltion_id from [digitalart_digitaltion] order by '+ @user_sort +' desc'
endselect @page_size as page_size, @page_order as page_order
select @sqlquery
execute (@sqlquery)
go
MSSQL 儲存過程分頁 測試 4
page size int 24,page order int 0 asset nocount on declare sqlquery varchar 1000 if page order 0 if user rank asc if user query begin set sqlquery sel...
MSSQL通用分頁儲存過程
分頁的儲存過程 create procedure getrecordfrompage tblname varchar 255 表名 fldname varchar 255 欄位名 pagesize int 10,頁尺寸 pageindex int 1,頁碼 iscount bit 0,返回記錄總數,...
MSSQL簡單的分頁儲存過程
drop table t1 create table t1 id int,s1 int insert into t1 values 1,4 insert into t1 values 2,5 insert into t1 values 3,5 insert into t1 values 4,4 in...
mssql高效的分頁儲存過程
最近在做一個幾百萬條資料的分頁查詢,研究了各種方案,在本機上用專案的實際資料庫做測試,測試過程 is very 痛苦,不堪回首ing。現在廢話不多說,直接上結果,相信這也是大多數搜尋答案的人最願意看的方式。create procedure dbo p gridviewpager recordtota...
MSSQL儲存過程
sqlserver 帶有返回值,儲存過程同時新增兩張表,並將第一張表的主鍵插入第二張表當中 2010 07 04 22 00 55 分類 sql 字號 訂閱 sql server 中,可以使用 scope identity identity ident current 來取得最後插入記錄的值值,它們...