from后面职能跟表、视图...,但就是不能跟变量!
应该这样:
CREATE PROCEDURE two
(
@col varchar(20),
@tab_name varchar(40)
)
AS
declare @strSQL varchar(2000)print @col
print @tab_name
set @strSQL='select '+@col+' from '+@tab_name
exec(@strSQL)
return
GO
应该这样:
CREATE PROCEDURE two
(
@col varchar(20),
@tab_name varchar(40)
)
AS
declare @strSQL varchar(2000)print @col
print @tab_name
set @strSQL='select '+@col+' from '+@tab_name
exec(@strSQL)
return
GO
以下是一个分页存储过程,但是我想把它作为一个通用的分页存储过程,即增加一个表名参数,
CREATE PROCEDURE page
(
@int_pagenow int=0, --当前页数
@int_pagesize int=0, --页面记录条数
@int_recordcount int=0 output --就是得出B版面的总贴数。。
)AS
set nocount ondeclare @int_allid int
declare @int_beginid int, @int_endid int
declare @int_pagebegin int, @int_pageend intselect @int_allid=count(*) from username
select @int_recordcount = @int_alliddeclare cro_fastread cursor scroll for
select id from username order by id descopen cro_fastread --打开游标
select @int_beginid=(@int_pagenow-1)*@int_pagesize+1 --得出该页的第一个纪录Id
select @int_endid = @int_beginid+@int_pagesize-1 --得出该页的最后一个纪录的Id
fetch absolute @int_beginid from cro_fastread into @int_pagebegin --将他的Id传给一个变量该页开始的Id
if @int_endid>@int_allid --这里要注意,如果某一页不足固定页数的纪录时。如只有一页纪录,而且纪录少于我们定义的数目。或者是最后一页时
fetch last from cro_fastread into @int_pageend --直接将游标绝对定位到最后一条纪录,得出他的id号来
else
fetch absolute @int_endid from cro_fastread into @int_pageendselect * from username where id between @int_pageend and @int_pagebegin order by id descclose cro_fastread
deallocate cro_fastread
GO但是,select @int_allid=count(*) from username按照以上的方法根本不可行,该怎么办啊。