根据关键字搜索的一个存贮过程

 


CREATE          PROCEDURE UP_FeedBack_Comment_KeyWord_Paged
@PageIndex INT, --开始页号
@PageSize INT,  --页数大小
@Keyword varchar(200),  --搜索关键字
@RecordCount INT OUT, --总记录数
@PageCount INT OUT --总页数
AS

SELECT @RecordCount = COUNT(*) FROM BZ_Data_Feedback  WHERE Context LIKE '%' + @Keyword + '%'

SET @PageCount = CEILING(@RecordCount * 1.0 / @PageSize)

DECLARE @SQLSTR NVARCHAR(1000)

IF @PageIndex = 0 OR @PageCount <= 1

SET @SQLSTR ='SELECT TOP '+STR( @PageSize )+' Feedback_ID, Context,SaveTime,FeedBack_Type FROM BZ_Data_Feedback WHERE Context LIKE ''%'+ @Keyword +'%'' ORDER BY Feedback_ID DESC'

ELSE IF @PageIndex = @PageCount - 1

SET @SQLSTR ='SELECT * FROM ( SELECT TOP '+STR( @RecordCount - @PageSize * @PageIndex )+' Feedback_ID, Context,SaveTime,FeedBack_Type FROM BZ_Data_Feedback WHERE Context LIKE ''%' + @Keyword + '%'' ORDER BY Feedback_ID ASC ) TempTable ORDER BY Feedback_ID DESC'

ELSE

SET @SQLSTR =' SELECT TOP '+STR( @PageSize )+' * FROM ( SELECT TOP '+STR( @RecordCount - @PageSize * @PageIndex )+' Feedback_ID, Context,SaveTime,FeedBack_Type FROM BZ_Data_Feedback WHERE Context LIKE ''%'+ @Keyword + '%'' ORDER BY Feedback_ID ASC ) TempTable ORDER BY Feedback_ID DESC'

EXEC (@SQLSTR)

GO

***********************2****************************
CREATE      PROCEDURE UP_FeedBack_Comment_Paged
@PageIndex INT, --????
@PageSize INT,  --????
@Feedback_id  int, --??ID
@RecordCount INT OUT, --????
@PageCount INT OUT --???
AS
SELECT @RecordCount = COUNT(*) FROM BZ_Data_Feedback_Comment WHERE Feedback_ID=@Feedback_id
SET @PageCount = CEILING(@RecordCount * 1.0 / @PageSize)
DECLARE @SQLSTR NVARCHAR(1000)
IF (@PageIndex = 0 OR @PageCount <= 1)
begin
SET @SQLSTR =' SELECT TOP  ' +   convert(varchar(5),@PageSize) + ' Feedback_Comment_ID,Feedback_ID,Context, SaveTime  FROM BZ_Data_Feedback_Comment  WHERE Feedback_ID= '+convert(varchar(18),@Feedback_id)+'  ORDER BY Feedback_Comment_ID DESC '
end
ELSE IF (@PageIndex = @PageCount - 1 )
begin
SET @SQLSTR =' SELECT * FROM ( SELECT TOP '+convert(varchar(5),( @RecordCount - @PageSize * @PageIndex ))+' Feedback_Comment_ID, Feedback_ID, Context,SaveTime FROM BZ_Data_Feedback_Comment WHERE Feedback_ID=  ' +convert(varchar(18), @Feedback_id) + '  ORDER BY Feedback_Comment_ID ASC ) TempTable ORDER BY Feedback_Comment_ID DESC'
end
ELSE
SET @SQLSTR =' SELECT TOP '+convert(varchar(5), @PageSize )+' * FROM ( SELECT TOP '+STR( @RecordCount - @PageSize * @PageIndex )+'Feedback_Comment_ID, Feedback_ID, Context,SaveTime FROM BZ_Data_Feedback_Comment WHERE Feedback_ID= ' + convert(varchar(18),@Feedback_id )+ '  ORDER BY Feedback_Comment_ID ASC ) TempTable ORDER BY Feedback_Comment_ID DESC'
EXEC (@SQLSTR)
GO

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值