日期:2014-05-18  浏览次数:20463 次

一个SQL2000的存储过程问题!!非常急,在线等
先说明一下,我是急用才碰到存储过程的,小弟实际一点都不懂。

我从网上找了一个自动生成的过程
然后我改了一点,改成
CREATE   procedure   newsList  
(@strwhere   NVarChar(1000),
@pagesize   int,
@pageindex   int,
@docount   bit)
as
set   nocount   on
if(@docount=1)
select   count(News_Date)   from   Table_news
else
begin
declare   @indextable   table(id   int   identity(1,1),nid   int)
declare   @PageLowerBound   int
declare   @PageUpperBound   int
declare   @NewTbles   varchar(1000)
set   @NewTbles=@strwhere
set   @PageLowerBound=(@pageindex-1)*@pagesize
set   @PageUpperBound=@PageLowerBound+@pagesize
set   rowcount   @PageUpperBound
insert   into   @indextable(nid)   select   News_ID   from   @NewTbles     order   by   News_Date   desc

select   *   from   @NewTbles   O,@indextable   t   where   O.News_ID=t.nid
and   t.id   between   @PageLowerBound+1   and   @PageUpperBound   order   by   t.id
end
set   nocount   off
GO
可是我一保存就提是我未声明变量
insert   into   @indextable(nid)   select   News_ID   from   @NewTbles     order   by   News_Date   desc
中的@NewTbles    

select   *   from   @NewTbles   O,@indextable   t   where   O.News_ID=t.nid
and   t.id   between   @PageLowerBound+1   and   @PageUpperBound   order   by   t.id
中的@NewTbles   。
可是,我在上边己经
declare   @NewTbles   varchar(1000)
set   @NewTbles=@strwhere
且通过了啊,谁能帮我看看,,求求大家了。。

------解决方案--------------------
from @NewTbles
這個變量需要表變量,之前定義的 declare @NewTbles varchar(1000)

------解决方案--------------------
CREATE procedure newsList
(@strwhere NVarChar(1000),
@pagesize int,
@pageindex int,
@docount bit)
as
set nocount on
if(@docount=1)
select count(News_Date) from Table_news
else
begin
--declare @indextable table(id int identity(1,1),nid int)
--对一Table 这个变量声明我没有用过,你可以过外面先建一个表,表名为@cc变量的值,
--我只会这么多,看一下有没有帮助
declare @cc varchar
declare @PageLowerBound int
declare @PageUpperBound int
declare @NewTbles varchar(1000)
declare @aa varchar(2000) --加入
declare @bb varchar(2000) --加入
set @NewTbles=@strwhere
set @PageLowerBound=(@pageindex-1)*@pagesize
set @PageUpperBound=@PageLowerBound+@pagesize
set rowcount @PageUpperBound


select @aa= 'insert into '+ @cc + ' select News_ID from '+ @NewTbles + 'order by News_Date desc '

exec @aa

select @bb= 'select * from '+@NewTbles + ' O, '+@cc+ ' t where O.News_ID=t.nid
and t.id between '+ @PageLowerBound+ '+1 and '+@PageUpperBound+ ' order by t.id '

exec @bb
end
set nocount off
GO

------解决方案--------------------
--試下看看,隨手寫的可能有錯
CREATE procedure newsList
(@strwhere NVarChar(1000),
@pagesize int,
@pageindex int,
@docount bit)
as
set nocount on
if(@docount=1)
select count(News_Date) from Table_news
else
begin
declare @indextable table(id int identity(1,1),nid int)
declare @PageLowerBound int
declare @PageUp