分页存储过程 字符串拼接 需加双重引号
create procedure up_deVbookSearchSplit2@pageStart int,
@pageCount int,
@Title1 varchar(200),
@pageAll int output
as
begin
declare @pageS int;
set @pageS=(@pageStart-1)*@pageCount+1;
declare @pageE int;
set @pageE=@pageStart*@pageCount;
declare @sql varchar(2000);
set @sql='select * from (select row_number() over(order by News_PKID) row,
Title,Cate_PKID from tNews where Title like%'+@Title1+'%)t
where t.row >='+cast(@pageS as varchar(20))+' and t.row<='+cast(@pageE as varchar(20))
set @pageAll=(select count(1) from tNews);
exec(@sql)
end
where Title like后应为'%+@Title1+%' 怎么在有引号的情况下加双重引号? --------------------编程问答-------------------- @Title1里有引号么? --------------------编程问答-------------------- 里面双的,外面单的里面双的
--------------------编程问答-------------------- @Title是字符串 --------------------编程问答-------------------- where Title like%'+replace(@Title1,"'","''")+'%)t --------------------编程问答-------------------- 这个是2000版的,拿去研究吧
--------------------编程问答-------------------- 谢谢大家!
CREATE PROCEDURE PrcTest
-- 获得某一页的数据 --
@currPage int = 1, --当前页页码 (即Top currPage)
@showColumn varchar(2000) = '*', --需要得到的字段 (即 column1,column2,......)
@tabName varchar(2000), --需要查看的表名 (即 from table_name)
@strCondition varchar(2000) = '', --查询条件 (即 where condition......) 不用加where关键字
@ascColumn varchar(100) = '', --排序的字段名 (即 order by column asc/desc)
@bitOrderType bit = 0, ---排序的类型 (0为升序,1为降序)
@pkColumn varchar(50) = '', --主键名称
@pageSize int = 20 --分页大小
AS
BEGIN -- 存储过程开始
-- 该存储过程需要用到的几个变量
DECLARE @strTemp varchar(1000)
DECLARE @strSql varchar(4000) --该存储过程最后执行的语句
DECLARE @strOrderType varchar(1000) --排序类型语句 (order by column asc或者order by column desc)
BEGIN
IF @bitOrderType = 1 -- bitOrderType=1即执行降序
BEGIN
SET @strOrderType = ' ORDER BY '+@ascColumn+' DESC'
SET @strTemp = '<(SELECT min'
END
ELSE
BEGIN
SET @strOrderType = ' ORDER BY '+@ascColumn+' ASC'
SET @strTemp = '>(SELECT max'
END
IF @currPage = 1 -- 如果是第一页
BEGIN
IF @strCondition != ''
SET @strSql = 'SELECT TOP '+STR(@pageSize)+' '+@showColumn+' FROM '+@tabName+
' WHERE '+@strCondition+@strOrderType
ELSE
SET @strSql = 'SELECT TOP '+STR(@pageSize)+' '+@showColumn+' FROM '+@tabName+@strOrderType
END
ELSE -- 其他页
BEGIN
IF @strCondition !=''
SET @strSql = 'SELECT TOP '+STR(@pageSize)+' '+@showColumn+' FROM '+@tabName+
' WHERE '+@strCondition+' AND '+@pkColumn+@strTemp+'('+@pkColumn+')'+' FROM (SELECT TOP '+STR((@currPage-1)*@pageSize)+
' '+@pkColumn+' FROM '+@tabName+@strOrderType+') AS TabTemp)'+@strOrderType
ELSE
SET @strSql = 'SELECT TOP '+STR(@pageSize)+' '+@showColumn+' FROM '+@tabName+
' WHERE '+@pkColumn+@strTemp+'('+@pkColumn+')'+' FROM (SELECT TOP '+STR((@currPage-1)*@pageSize)+' '+@pkColumn+
' FROM '+@tabName+@strOrderType+') AS TabTemp)'+@strOrderType
END
END
EXEC (@strSql)
END -- 存储过程结束
--prcPageResult 1,'*','TableName','','CreateDate',1,'PkID',25
/*
下面的存储过程查询表的记录数
CREATE PROC prcRowsCount
@tabName varchar(200), --需要查询的表名
@colName varchar(200)='*', --需要查询的列名
@condition varchar(200)='' --查询条件
AS
BEGIN
DECLARE @strSql varchar(255)
IF @condition = ''
SET @strSql='select count('+@colName+') from '+@tabName
ELSE
SET @strSql='select count('+@colName+') from '+@tabName+' where '+@condition
EXEC (@strSql)
END
*/
GO
补充:.NET技术 , ASP.NET