今儿改的
2009-12-14 17:20 cnb_mtime 阅读(194) 评论(0) 编辑 收藏 举报select title from Bao_ZhaoShang where Title like '%胶囊%'
SELECT TOP 10 bu.Companyname,bu.QQ,bz.ID,bz.UserID,bz.Title,bz.Types,bz.propic,bz.Province,bz.addtime,bz.biaozhun,bz.Hits
from Bao_Zhaoshang bz,Bao_User bu
where bz.UserID = bu.UserID and bz.IsShenHe = 1 and bz.title like '%胶囊%' and bz.id<(SELECT min(id) FROM (SELECT TOP 10 bz.id FROM Bao_Zhaoshang bz where bz.IsShenHe = 1 and bz.title like '%胶囊%' order by Addtime desc) AS TabTemp)
order by Addtime desc
EXEC GetDataPager 'Bao_Zhaoshang bz','bz.ID,bz.UserID','AddTime',10,2,1,1,'Title like ''%胶囊%'' and IsShenHe = 1 '
EXEC getUserbyID 16
CREATE PROCEDURE getUserbyID
@UserID int
as
declare @strSQL nvarchar(4000) -- 主语句
begin
set @strSQL = 'Select UserID,QQ,CompanyName from Bao_User where UserID ='+ str(@UserID)
end
exec (@strSQL)
go
CREATE PROCEDURE GetDataPager
@tblName varchar(255), -- 表名
@strGetFields varchar(1000) = '*', -- 需要返回的列
@fldName varchar(255)='', -- 排序的字段名
@PageSize int = 10, -- 页尺寸
@PageIndex int = 1, -- 页码
@doCount bit = 0, -- 返回记录总数, 非 0 值则返回
@OrderType bit = 0, -- 设置排序类型, 非 0 值则降序
@strWhere nvarchar(1000) = '' -- 查询条件 (注意: 不要加 where)
AS
declare @strSQL nvarchar(4000) -- 主语句
declare @strTmp varchar(110) -- 临时变量
declare @strOrder varchar(400) -- 排序类型
if @doCount != 0 --如果@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'
--如果@OrderType不是0,就执行降序
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
--以下代码赋予了@strSQL以真正执行的SQL代码
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