本帖最后由 黑马-杨鹏立 于 2013-3-2 00:39 编辑
ALTER PROCEDURE [dbo].[GetCaseContentPageDataOutRowPageCount2]
(
@PageIndex int = 1,--当前页数
@PageSize int = 4,--每页大小
@strKey nvarchar =N'a',
@RowCount int output,--总行数(传出参数)
@PageCount int output--总页数(传出参数)
)
AS
begin
DECLARE @sql NVARCHAR(max)
select @RowCount =COUNT(FCaseChildId),@PageCount=CEILING((COUNT(FCaseChildId)+0.0)/@PageSize) FROM TCaseContent where FImagDescribe like (N'''%'+@strKey+'%''') 错误的 应改为N'%'+@strKey+'%'
SET @sql='SELECT TOP '+LTRIM(str(@PageSize))+' * FROM TCaseContent where FImagDescribe like N'+'''%'+@strKey+'%'''+' and FCaseChildId not in(select top '+LTRIM(str((@PageIndex-1)*@PageSize))+' FCaseChildId from TCaseContent where FImagDescribe like N'+'''%'+@strKey+'%'' )'
print @sql
EXEC(@sql)
end
declare @RC int,@Pc int
exec GetCaseContentPageDataOutRowPageCount2 1,10,N'e',@RC output,@PC output
select @RC,@PC
执行结果为
去掉 (where FImagDescribe like N'''%'+@strKey+'%''') 后 select @RowCount =COUNT(FCaseChildId),@PageCount=CEILING((COUNT(FCaseChildId)+0.0)/@PageSize) FROM TCaseContent
结果为
为什么我加where后输出参数不能用了呢??什么情况?????? 额.....额...熬夜太晕了...多了分号居然不知道where FImagDescribe like N'''%'+@strKey+'%''' 改为like N'%'+@strKey+'%'这样就解决了 我在存储过程中拼接字符串花的时间比较多有个地方值得注意.... N'+'''%'+@strKey+'%'''+这里拼接得注意分号
|
|