首页上一页 1 下一页尾页 1 条记录 1/1页
第 1 行: '-' 附近有语法错误。
发表在ASP.NET图书答疑
2014-04-29
是否精华
是
否
版块置顶:
是
否
/*
@tblName varchar(255), -- 表名
//@strGetFields varchar(1000) = '*', -- 需要返回的列
//@fldName varchar(255)='', -- 排序的字段名
//@PageSize int = 10, -- 页尺寸
//@PageIndex int = 1, -- 页码
//@doCount bit = 0, -- 返回记录总数, 非 0 值则返回
//@OrderType bit = 0, -- 设置排序类型, 非 0 值则降序
//@strWhere varchar(1500) = '' -- 查询条件 (注意: 不要加 where)
//如:返回记录明细:
// exec bs_proc_pagedata 'wldoc','no,name,bikedoc,cddoc,unitdoc,price,pprice,sprice','id',20,2,0,0,'no like ''12%'''
//如:返回记录总数:
// exec bs_proc_pagedata 'wldoc','no,name,bikedoc,cddoc,unitdoc,price,pprice,sprice','id',20,2,1,0,'no like ''12%'''
*/
CREATE proc bspagedata
@tblName varchar(255), -- 表名
@strGetFields varchar(1000) = '*', -- 需要返回的列
@fldName varchar(255)='', -- 排序的字段名
@PageSize int = 10, -- 页尺寸
@PageIndex int = 1, -- 页码
@doCount bit = 0, -- 返回记录总数, 非 0 值则返回
@OrderType bit = 0, -- 设置排序类型, 非 0 值则降序
@strWhere varchar(1500) = '' -- 查询条件 (注意: 不要加 where)
AS
declare @strSQL varchar(5000)
declare @strTmp varchar(110)
declare @strOrder varchar(400)
if @doCount != 0
begin
if @strWhere !=' '
set @strSQL = ' select count(*) as Total from [' + @tblName + '] where '+@strWhere
else
set @strSQL = ' select count(*) as Total from [' + @tblName + '] '
end
else
begin
if @OrderType != 0
begin
set @strTmp = ' <(select min'
set @strOrder = ' order by [' + @fldName +'] desc '
end
else
begin
set @strTmp = ' >(select max'
set @strOrder = ' order by [' + @fldName +'] asc '
end
if @PageIndex = 1
begin
if @strWhere != ''
set @strSQL = ' select top ' + str(@PageSize) +' '+@strGetFields+ ' from [' + @tblName + '] where '+ @strWhere + ' ' + @strOrder
else
set @strSQL = ' select top ' + str(@PageSize) +' '+@strGetFields+ ' from ['+ @tblName + '] '+ @strOrder
end
else
begin
set @strSQL = ' select top ' + str(@PageSize) +' '+@strGetFields+ ' from ['+ @tblName + '] where [' + @fldName + ']'
+ @strTmp + '(['+ @fldName + ']) from (select top ' + str((@PageIndex-1)*@PageSize) + ' ['+ @fldName + '] from [' + @tblName + ']' + @strOrder + ') as tblTmp)'+ @strOrder
if @strWhere != ''
set @strSQL = ' select top ' + str(@PageSize) +' '+@strGetFields+ ' from ['
+ @tblName + '] where [' + @fldName + ']' + @strTmp + '(['
+ @fldName + ']) from (select top ' + str((@PageIndex-1)*@PageSize) + ' [' + @fldName + '] from [' + @tblName + '] where ' + @strWhere + ' '
+ @strOrder + ') as tblTmp) and ' + @strWhere + ' ' + @strOrder
end
end
exec (@strSQL)
GO
@tblName varchar(255), -- 表名
//@strGetFields varchar(1000) = '*', -- 需要返回的列
//@fldName varchar(255)='', -- 排序的字段名
//@PageSize int = 10, -- 页尺寸
//@PageIndex int = 1, -- 页码
//@doCount bit = 0, -- 返回记录总数, 非 0 值则返回
//@OrderType bit = 0, -- 设置排序类型, 非 0 值则降序
//@strWhere varchar(1500) = '' -- 查询条件 (注意: 不要加 where)
//如:返回记录明细:
// exec bs_proc_pagedata 'wldoc','no,name,bikedoc,cddoc,unitdoc,price,pprice,sprice','id',20,2,0,0,'no like ''12%'''
//如:返回记录总数:
// exec bs_proc_pagedata 'wldoc','no,name,bikedoc,cddoc,unitdoc,price,pprice,sprice','id',20,2,1,0,'no like ''12%'''
*/
CREATE proc bspagedata
@tblName varchar(255), -- 表名
@strGetFields varchar(1000) = '*', -- 需要返回的列
@fldName varchar(255)='', -- 排序的字段名
@PageSize int = 10, -- 页尺寸
@PageIndex int = 1, -- 页码
@doCount bit = 0, -- 返回记录总数, 非 0 值则返回
@OrderType bit = 0, -- 设置排序类型, 非 0 值则降序
@strWhere varchar(1500) = '' -- 查询条件 (注意: 不要加 where)
AS
declare @strSQL varchar(5000)
declare @strTmp varchar(110)
declare @strOrder varchar(400)
if @doCount != 0
begin
if @strWhere !=' '
set @strSQL = ' select count(*) as Total from [' + @tblName + '] where '+@strWhere
else
set @strSQL = ' select count(*) as Total from [' + @tblName + '] '
end
else
begin
if @OrderType != 0
begin
set @strTmp = ' <(select min'
set @strOrder = ' order by [' + @fldName +'] desc '
end
else
begin
set @strTmp = ' >(select max'
set @strOrder = ' order by [' + @fldName +'] asc '
end
if @PageIndex = 1
begin
if @strWhere != ''
set @strSQL = ' select top ' + str(@PageSize) +' '+@strGetFields+ ' from [' + @tblName + '] where '+ @strWhere + ' ' + @strOrder
else
set @strSQL = ' select top ' + str(@PageSize) +' '+@strGetFields+ ' from ['+ @tblName + '] '+ @strOrder
end
else
begin
set @strSQL = ' select top ' + str(@PageSize) +' '+@strGetFields+ ' from ['+ @tblName + '] where [' + @fldName + ']'
+ @strTmp + '(['+ @fldName + ']) from (select top ' + str((@PageIndex-1)*@PageSize) + ' ['+ @fldName + '] from [' + @tblName + ']' + @strOrder + ') as tblTmp)'+ @strOrder
if @strWhere != ''
set @strSQL = ' select top ' + str(@PageSize) +' '+@strGetFields+ ' from ['
+ @tblName + '] where [' + @fldName + ']' + @strTmp + '(['
+ @fldName + ']) from (select top ' + str((@PageIndex-1)*@PageSize) + ' [' + @fldName + '] from [' + @tblName + '] where ' + @strWhere + ' '
+ @strOrder + ') as tblTmp) and ' + @strWhere + ' ' + @strOrder
end
end
exec (@strSQL)
GO