日期:2013-09-15  浏览次数:21078 次

CREATE PROCEDURE [dbo].[Select_page_data_allow_fields_cond]
@allow_fields varchar(100) =" * ",
@DefRecordNum int =20,
@PageNo int =1,
@Where varchar(500) = null
AS
declare @R_end int
declare @S_sql varchar(500)
declare @condition varchar(500)
declare @condition2 varchar(500)


--if rtrim(@Where)!=""
--if rtrim(@Where)!=""

SET @r_end=(@PageNo-1)*@DefRecordNum+1

--正则页码
IF ( CAST(@r_end AS INT)<1)
SET @r_end = 1

SET @Where=rtrim(@Where)
--if not (@Where is null )
if (@Where <>'' )
SET @S_sql="SELECT TOP "+CAST(@DefRecordNum AS CHAR(4)) +space(2)+@allow_fields+" FROM BBSReply WHERE id>=(SELECT MAX(ID) AS r_begin FROM (SELECT TOP "+CAST(@R_end AS CHAR(5))+" ID FROM BBSReply WHERE "+@Where+" ORDER BY ID) airzen) AND "+@Where+" order by id"
ELSE
SET @S_sql="SELECT TOP "+CAST(@DefRecordNum AS CHAR(4)) +space(2)+@allow_fields+" FROM BBSReply WHERE id>=(SELECT MAX(ID) AS r_begin FROM (SELECT TOP "+CAST(@R_end AS CHAR(5))+" ID FROM BBSReply ORDER BY ID) airzen) order by id"

--PRINT @S_sql
EXEC(@S_sql)
GO




---------------------------------------------------

<%
'********************************************************************
'本程序由AIRZEN 2004/5/12 更新修定。
'===================================================================
Option Explicit
'Response.Flush
Dim BeginTime,EndTime
BeginTime=Timer
Dim conn,SQLstr,Rs,DefRecordNum,CursorBegin,CursorEnd,CurPageNum,hav
DefRecordNum=20
dim R_end
'--------------获取相关参数----------
If Request("CurPageNum")<>"" Then
CurPageNum=CLng(Request("CurPageNum"))
If CurPageNum<=0 Then CurPageNum=1
Else
CurPageNum=1
End If



'----------------End-----------------
'------------显示翻页内容函数--------
Function TurnPageFS(DispRecordNum)
Dim n
While Not(Rs.Eof) And n<DispRecordNum
n=n+1
Response.Write "<tr>"&_
"<td bgcolor='efefef'>"&n&"</td>"&_
"<td bgcolor='efefef'>"&Rs(0)&"</td>"&_
"<td bgcolor='efefef'>"&Rs(1)&"</td>"&_
"<td bgcolor='efefef'>"&Rs(2)&"</td>"&_
"<td bgcolor='efefef'>"&Rs(3)&"</td>"&_
"<td bgcolor='efefef'>"&Rs(4)&"</td>"&_
"<td bgcolor='efefef'>"&Rs(5)&"</td>"&_
"</tr>"
If n=1 Then CursorBegin=Rs(0)
If n=DefRecordNum Or Rs.Eof Then CursorEnd=Rs(0)
Rs.MoveNext
Wend
End Function
'-------------连接数据库-------------
Set conn=Server.CreateObject("Adodb.Connection")
'SQLstr="Provider=Microsoft.Jet.OLEDB.4.0;Data Source="&Server.Mappath("mldata.mdb")
SQLstr="provider=SQLOLEDB;server=(local);database=XX;uid=XX;pwd=XX;"
conn.Open SQLstr
Dim TotalRecords,TotalPages

TotalPages=clng(request.QueryString("TotalPages"))

'//判断有无接收的页码
if TotalPages=0 or not isnumeric(TotalPages) then '//无接收页码

SQLstr="Select count(ID) As RecordSum From BBSreply WHERE userid='airzen'" '//此条件应与下面的存储过程条件保持一持
Set Rs=conn.Execute(SQLstr,0,1)
TotalRecords=Rs("RecordSum")
TotalPages=Abs(Int(TotalRecords/DefRecordNum*(-1)))
Rs.Close
Set Rs=Nothing

end if
dim allow_fields
'//允许控制选择的字段以最优化的SQL 语句执行,
'//allow_fields :允许的字段
'//DefRecordNum :每页显示的记录数目
'//CurPageNum :当前页码
allow_fields="[*]"
if TotalPages<1 then TotalPages=1
SQLstr="Select_page_data_allow_fields_cond "&allow_fields&"