分頁加搜尋sql語句

2022-04-29 08:03:07 字數 2094 閱讀 8733

--分頁儲存過程

if (object_id('pro_page', 'p') is

notnull)

drop

proc pro_stu

gocreate

procedure pro_stu(

@pageindex int,

@pagesize int)as

declare @startrow int, @endrow int

set @startrow = (@pageindex - 1) * @pagesize +1

set @endrow = @startrow + @pagesize -1

select * from (

select *, row_number() over (order

by id asc) as number from student

) twhere t.number between @startrow and @endrow;

exec pro_stu 2, 2;

1.此種方法是先查詢出所需要的資料**再新增序列號no(分頁搜尋時推薦使用這種)

select t.* from(

select row_number() over(order by xm desc) as no,a.* from (        //將a表加上序列號

select * from rzsh where 1=1 sqlwhere) as a

) as t 

where t.no>startindex and t.no2.此種方法是將**新增序列號再進行查詢(此種弊端是sqlwhere搜尋後的資料不是從1開始(因為已經在搜尋前編過序號了),若查詢出的資料是12-15行的,而t.no>1 and t.no<10,則不能顯示或顯示不全)

select * from (

select * from (

select row_number() over(order by sbrq desc) as no,* from rzsh

) as a  where 1=1  and xm like '%飛%'

) as t 

where t.no>0 and t.no<11

前台頁面

後台

//當定資料和分頁

public void binddata()

if (txtaddress.text.trim() != "")

if (txtdate.text.trim() != "")

//int index = convert.toint32(viewstate["index"].tostring());

int index = aspnetpager1.currentpageindex;

datatable dt = sbsh.getview(sqlwhere).tables[0];

dataset ds = sbsh.getviewbypage(sqlwhere, "sbrq desc", (index - 1) * 10, (index - 1) * 10 + 11);

aspnetpager1.recordcount = dt.rows.count;

aspnetpager1.pagesize = 10;

repeater1.datasource = ds.tables[0];

repeater1.databind();

for (int i = 0; i < this.repeater1.items.count; i++)}}

//當前頁索引改變事件

protected void aspnetpager1_pagechanged(object sender, eventargs e)

//繫結審核狀態

public string bindshzt(string shzt)

else

}protected void repeater1_itemcommand(object source, repeatercommandeventargs e)

}//搜尋

protected void btnsearch_click(object sender, eventargs e)

Sql 分頁語句

with temptb as select row number over order by id as rowid,from pagecut select from temptb where rowid between 2 50 and 2 50 50 這是乙個資料分頁方法,從sql2005起就支...

SQL分頁語句

這個分頁方法 sql分頁語句 本人對原作者的方案二做了小小的改動 原語句 select top 頁大小 from table1 where id select isnull max id 0 from select top 頁大小 頁數 1 id from table1 order by id a ...

SQL分頁語句

有關分頁 sql 的資料很多,有的使用儲存過程,有的使用游標。本人不喜歡使用游標,我覺得它耗資 效率低 使用儲存過程是個不錯的選擇,因為儲存過程是經過預編譯的,執行效率高,也更靈活。先看看單條 sql 語句的分頁 sql 吧。方法1 適用於 sql server 2000 2005 select t...