标题:语``问题
取消只看楼主
copy462829
Rank: 1
等 级:新手上路
帖 子:112
专家分:0
注 册:2007-1-31
 问题点数:0 回复次数:3 
语``问题
set @strJoin=' Re_Name like ''%'+rtrim(@caption)+'%''' --

select @RecordCount=count(*) from Regimental where @strJoin --

运行的时候 上句错误 怎么样的写法 才能得倒我要想要的出 ,请大家多多指点
2007-02-08 14:11
copy462829
Rank: 1
等 级:新手上路
帖 子:112
专家分:0
注 册:2007-1-31
得分:0 

没有读值,是空的

2007-02-08 20:38
copy462829
Rank: 1
等 级:新手上路
帖 子:112
专家分:0
注 册:2007-1-31
得分:0 

create proc RegimentalSearch
@caption nvarchar(100),--标题
@PageSize int,--页大小
@PageIndex int, --多少页
@WordLength int
as
begin
declare @RecordCount int --行
declare @PageCount int --页

declare @str nvarchar(1000) --运行参数
declare @strJoin nvarchar(500) --存放条件
if(@caption != '')
begin
set @strJoin=' Re_Name like ''%'+rtrim(@caption)+'%'''
end
else
begin
set @strJoin='Re_ID=0' --显示空' '
end
declare @aa nvarchar(100)
exec('select '+'''@RecordCount'''+' = count(*) from Regimental where'+ @strJoin) --反回行

print(@RecordCount)

set @PageCount=ceiling(@RecordCount*1.0/@PageSize)

--RecordCount和PageCount打印出来是空的
如果不要exec,写成 select @RecordCount=count(*) from Regimental where @strJoin 请问这句怎么写才对

2007-02-08 20:42
copy462829
Rank: 1
等 级:新手上路
帖 子:112
专家分:0
注 册:2007-1-31
得分:0 

create proc RegimentalSearch
@caption nvarchar(100),--标题
@PageSize int,--页大小
@PageIndex int, --多少页
@WordLength int
as
begin
declare @RecordCount int --行
declare @PageCount int --页

declare @str nvarchar(1000) --运行参数
declare @strJoin nvarchar(500) --存放条件
if(@caption != '')
begin
set @strJoin=' Re_Name like ''%'+rtrim(@caption)+'%'''
end
else
begin
set @strJoin='Re_ID=0'
end
declare @aa nvarchar(100)
exec('select '+'''@RecordCount'''+' = count(*) from Regimental where'+ @strJoin) --反回行

print @RecordCount

set @PageCount=ceiling(@RecordCount*1.0/@PageSize)


print @PageCount


if @PageIndex=0 or @PageCount<=1
begin
set @str='select top'+str(@PageSize)+' a.Re_ID,
case when len(a.Re_Name)>'+str(@WordLength)+' then substring (a.Re_Name,0,'+str(@WordLength)+')+''...''
else a.Re_Name end as name
,a.Re_Time,(select Co_ClassName from CoAskClass where Co_ID =a.Re_Type) as leixing ,a.Re_Count from Regimental as a where '+@strJoin+'order by a.Re_Count desc'

end
else if @PageIndex=@PageCount-1
begin

set @str='select * from (select top '+str(@RecordCount-@PageSize*@PageIndex)+' a.Re_ID,
case when len(a.Re_Name)>'+str(@WordLength)+' then substring (a.Re_Name,0,'+str(@WordLength)+')+''...''
else a.Re_Name end as name
,a.Re_Time,(select Co_ClassName from CoAskClass where Co_ID =a.Re_Type) as leixing ,a.Re_Count from Regimental as a where '+@strJoin+'order by a.Re_Count asc) temptable order by Re_Count desc '
end
else
begin

set @str='select top'+str(@PageSize)+' * from(select top'+str( @RecordCount - @PageSize * @PageIndex)+' a.Re_ID,
case when len(a.Re_Name)>'+str(@WordLength)+' then substring (a.Re_Name,0,'+str(@WordLength)+')+''...''
else a.Re_Name end as name
,a.Re_Time,(select Co_ClassName from CoAskClass where Co_ID =a.Re_Type) as leixing ,a.Re_Count from Regimental as a where '+@strJoin+'order by a.Re_Count asc) temptable order by Re_Count desc '
end
exec(@str)
end

-- @RecordCount @PageCount没有打印值,
-- exec exec('select '+'''@RecordCount'''+' = count(*) from Regimental where'+ @strJoin) 返回 @RecordCount=2 ,问题我没给这列起别名,
-- 打印无值 --主要的问题是他不变量赋值,@RecordCount=null

2007-02-10 17:41



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-120210-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.583689 second(s), 8 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved