好湿?好紧?好多水好爽自慰,久久久噜久噜久久综合,成人做爰A片免费看黄冈,机机对机机30分钟无遮挡

主頁 > 知識庫 > 分頁存儲過程代碼

分頁存儲過程代碼

熱門標簽:福州外呼系統招商 商家地圖標注圖片 沈陽外呼系統有效果嗎 電話機器人接口是什么樣的 溫州語音外呼系統排名 AI智能云呼電話機器人怎么注冊 怎么在高德地圖標注多個點 百度地圖標注信息怎么修改 四川穩定外呼系統公司
復制代碼 代碼如下:

/*
*@curentpage 當前頁
*@pagesize 每頁記錄數
*@TableName 表名
*@key 主鍵(自動排序)
*@where 查詢條件
1)空為 null
2)有查詢條件不要帶where
*@order '0'表示 desc '1'是asc
*@pageCount 總頁數
*/
create procedure Page
@currentpage int,@pagesize int,
@TableName varchar(30),@key varchar(30),
@where varchar(50),@order varchar(1),
@pageCount int ,@str varchar(450) output
as
begin
---------------執行的sql語句------------
declare @sql nvarchar(400),@ordreby nvarchar(200)
declare @tempsql1 varchar(200),@tempsql2 varchar(200)
---------------記錄總數-----------------
declare @count int
---------------臨時變量------------------------
declare @temp1 int,@temp2 int

set @TableName=' '+@TableName+' '
set @key=' '+@key+' '

if @order='0'
set @ordreby=' order by '+@key+'desc'
else
set @ordreby=' order by '+@key

if @where='null'
set @sql='select @count = count(*) from '+ @TableName
else
set @sql='select @count = count(*) from '+ @TableName+' where '+@where

------------@count 付值(聲明變量@count 在說明是output 內型)---------------------------
exec sp_executesql @sql,N'@count int out',@count out
------------求總頁數------------------------------
if (@count%@pagesize)=0
set @pagecount=@count/@pagesize
else
set @pagecount=@count/@pagesize+1
-----------判斷顯示當前頁是否異常------------------
if @currentpage>@pagecount
set @currentpage=@pagecount
if @currentpage1
set @currentpage=1
----------記錄數小于頁面顯示記錄數-----------------
if(@currentpage=1)
begin
if @where='null'
set @where=' '
else
set @where=' where '+@where
set @sql = 'select top'+ str(@pagesize)+' * from '+@TableName+@where+@ordreby
end
else
begin
/**//* ---------------desc----------------------
*@temp1表示前面的記錄
*@temp2表示后面的記錄
*假設一共77個記錄,每次取10個。取67~58(第2頁),去掉前面的57(1~57)個和后面的10個(77~66)
*/
if @order=0
begin
set @temp1 = @count-@currentpage*@pagesize
if @temp10
set @temp1=0
set @temp2 = (@currentpage - 1)*@pagesize
if @where='null'
begin
set @tempsql1='select top ' + str(@temp1)+' '+@key+' from ' + @TableName+' order by ' +@key
set @tempsql2='select top ' + str(@temp2)+' '+@key+' from ' + @TableName + @ordreby
end
else
begin
set @tempsql1='select top ' + str(@temp1)+' '+@key+' from ' + @TableName+' where '+@where+' order by ' +@key
set @tempsql2='select top ' + str(@temp2)+' '+@key+' from ' + @TableName+' where '+@where+@ordreby
end
set @sql=' select top ' + str(@pagesize) + ' * from ' + @TableName + ' where '+@key+ ' not in '
set @sql= @sql+' ( '+ @tempsql1 +' ) and '
set @sql= @sql+@key+ ' not in ( '+@tempsql2 +' ) '
if @where='null'
set @sql= @sql+@ordreby
else
set @sql= @sql+' and '+@where+@ordreby
end
/**//* ----------------asc---------------------
* @temp 表示前面顯示的記錄總數
* 去掉 @temp 在取出 pagesize 個即可
*/
else
begin
set @temp1=(@currentpage-1)*@pagesize
if @where='null'
set @tempsql1='select top '+ str(@temp1)+' '+@key+' from ' + @TableName + @ordreby
else
set @tempsql1='select top '+ str(@temp1)+' '+@key+' from ' + @TableName ++' where '+@where+@ordreby
set @sql=' select top ' + str(@pagesize) + ' * from ' + @TableName + ' where '+@key+ ' not in '
set @sql=@sql+' ( '+@tempsql1+' ) '
if @where='null'
set @sql= @sql+@ordreby
else
set @sql= @sql+' and '+@where+@ordreby

end
/**//* -------------------------------------*/
end
set @str=@sql
--exec sp_executesql @sql

end

GO

標簽:七臺河 寶雞 汕尾 來賓 無錫 邯鄲 西寧 營口

巨人網絡通訊聲明:本文標題《分頁存儲過程代碼》,本文關鍵詞  分頁,存儲,過程,代碼,分頁,;如發現本文內容存在版權問題,煩請提供相關信息告之我們,我們將及時溝通與處理。本站內容系統采集于網絡,涉及言論、版權與本站無關。
  • 相關文章
  • 下面列出與本文章《分頁存儲過程代碼》相關的同類信息!
  • 本頁收集關于分頁存儲過程代碼的相關信息資訊供網民參考!
  • 推薦文章