select @RecordCount=count(*) from Regimental where @strJoin --
运行的时候 上句错误 怎么样的写法 才能得倒我要想要的出 ,请大家多多指点
没有读值,是空的
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 请问这句怎么写才对
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