- Rongsen.Com.Cn 版权所有 2008-2010 京ICP备08007000号 京公海网安备11010802026356号 朝阳网安编号:110105199号
- 北京黑客防线网安工作室-黑客防线网安服务器维护基地为您提供专业的
服务器维护
,企业网站维护
,网站维护
服务 - (建议采用1024×768分辨率,以达到最佳视觉效果) Powered by 黑客防线网安 ©2009-2010 www.rongsen.com.cn
作者:黑客防线网安SQL维护基地 来源:黑客防线网安SQL维护基地 浏览次数:0 |
CREATE PROCEDURE [dbo].[USP_GetList]
(
@pageIndex int = 1 -- 当前页码0 表示返回所有符合内容
,@pageSize int = 10 -- 页尺寸
,@SID nvarchar(30) = '' -- 主键字段
,@strGetField nvarchar(1000) = '*' -- 需要返回的列
,@strTableName nvarchar(30) = '' --表名
,@strWhere nvarchar(2000) = '' -- 查询条件(注意: 条件中要带where)
,@strOrderBy nvarchar(300) = '' -- 排序
--,@MemberID int=0 --会员ID
)
AS
SET NOCOUNT ON
DECLARE @strSQL nvarchar(4000)
DECLARE @startPos int
DECLARE @endPos int
DECLARE @num int
SET @startPos=@pageSize*(@pageIndex-1)+1
SET @endPos=@startPos+@pageSize-1
--页大小*(页数-1)
SET @num = @pageSize * (@PageIndex - 1)
IF @PageIndex!=0
BEGIN
IF @strWhere != ''
SET @strSQL = 'SELECT TOP '+ cast(@pageSize as nvarchar(10)) +' '+ @strGetField +' FROM '+ @strTableName +' WHERE ('+ cast(@SID as nvarchar(30)) +' NOT IN (SELECT TOP '+ cast(@num as nvarchar(20)) +' '+ cast(@SID as nvarchar(30)) +' FROM '+ @strTableName +' where '+@strWhere+' ORDER BY '+ cast(@strOrderBy as nvarchar(255)) +' )) and '+@strwhere+' ORDER BY '+cast(@strOrderBy as varchar(255)) + ''
else
SET @strSQL = 'SELECT TOP '+ cast(@pageSize as nvarchar(10)) +' '+ @strGetField +' FROM '+ @strTableName +' WHERE ('+ cast(@SID as nvarchar(30)) +' NOT IN (SELECT TOP '+ cast(@num as nvarchar(20)) +' '+ cast(@SID as nvarchar(30)) +' FROM '+ @strTableName +' ORDER BY '+ cast(@strOrderBy as nvarchar(255)) +' )) ORDER BY '+ cast(@strOrderBy as varchar(255)) + ''
--SET @strSQL = 'SELECT TOP 页大小 * FROM Users WHERE (ID NOT IN (SELECT TOP (页大小*(当前页-1)) ID FROM Users ORDER BY ID DESC )) ORDER BY ID DESC'
END
ELSE
BEGIN
IF @strWhere != ''
SET @strSQL = 'select '+ @strGetField +' from ' + @strTableName + ' where '+ @strWhere +' order by '+ @strOrderBy
ELSE
SET @strSQL = 'select '+ @strGetField +' from ' + @strTableName + ' order by '+ @strOrderBy
END
--print(@strSQL)
EXEC(@strSQL)
GO
第二个存储过程
CREATE PROCEDURE [dbo].[USP_GetTotal]
(
@strTableName nvarchar(30) = '',
@strWhere nvarchar(2000) = '' -- 查询条件(注意: 条件中要带where)
)
AS
SET NOCOUNT OFF
DECLARE @strSQL nvarchar(2500)
IF @strWhere != ''
SET @strSQL = 'select count(*) as Total from ['+ @strTableName +'] where '+ @strWhere
ELSE
SET @strSQL = 'select count(*) as Total from ['+ @strTableName +']'
EXEC(@strSQL)
GO
下面是调用这个存储过程的两个函数。可以放到一个包含文件里
,注意,下面的函数里面使用的一些变量,是全局的变量,不是参数传入的,所以需要在调用函数钱,给全局变量赋值。
<%
'取记录总数存储过程
public function getDataRowCount(strTableName, strWhere)
dim maxCount
dim myobj
dim rsCount
maxCount = 0
Set myobj = Server.CreateObject("ADODB.Command")
with myobj
.ActiveConnection = conn
.CommandText = "USP_GetTotal"
.CommandType = 4
.Prepared = true
.Parameters.append .CreateParameter("@strTableName", 200, 1, 30,
我要申请本站:N点 | 黑客防线官网 | |
专业服务器维护及网站维护手工安全搭建环境,网站安全加固服务。黑客防线网安服务器维护基地招商进行中!QQ:29769479 |