sql server 2000 存储过程 @where附近有语法错误
begindeclare@indextabletable(idintidentity(1,1),nidint)declare@PageLowerBoundintdecla...
begin
declare @indextable table(id int identity(1,1),nid int)
declare @PageLowerBound int
declare @PageUpperBound int
set @PageLowerBound=(@pageindex-1)*@pagesize+1
set @PageUpperBound=@PageLowerBound+@pagesize
set rowcount @PageUpperBound
insert into @indextable(nid) select Id from product where 1=1 @where order by Id desc
select * from product O,@indextable t where where 1=1 @where and O.Id=t.nid and t.id between @PageLowerBound and @PageUpperBound-1 order by t.id desc
end
@where是传递进来的查询条件,提示@where附近有语法错误
该怎么改? 展开
declare @indextable table(id int identity(1,1),nid int)
declare @PageLowerBound int
declare @PageUpperBound int
set @PageLowerBound=(@pageindex-1)*@pagesize+1
set @PageUpperBound=@PageLowerBound+@pagesize
set rowcount @PageUpperBound
insert into @indextable(nid) select Id from product where 1=1 @where order by Id desc
select * from product O,@indextable t where where 1=1 @where and O.Id=t.nid and t.id between @PageLowerBound and @PageUpperBound-1 order by t.id desc
end
@where是传递进来的查询条件,提示@where附近有语法错误
该怎么改? 展开
1个回答
展开全部
insert into @indextable(nid) select Id from product where 1=1 @where order by Id desc
select * from product O,@indextable t where where 1=1 @where and O.Id=t.nid and t.id between @PageLowerBound and @PageUpperBound-1 order by t.id desc
end
你先把上面这两个串赋值给字符串,然后打印看看语法是不是正确,一般应该是组合的时候形成了未考虑到的字符串造成的。
sql = insert into @indextable(nid) select Id from product where 1=1 @where order by Id desc
print sql
select * from product O,@indextable t where where 1=1 @where and O.Id=t.nid and t.id between @PageLowerBound and @PageUpperBound-1 order by t.id desc
end
你先把上面这两个串赋值给字符串,然后打印看看语法是不是正确,一般应该是组合的时候形成了未考虑到的字符串造成的。
sql = insert into @indextable(nid) select Id from product where 1=1 @where order by Id desc
print sql
追问
在sql server企业管理器里检查语法提示的错误,还没有传递查询条件
追答
where 1=1 @where 你这一句@where 本来就是多余的,1=1就相当于一个true条件,如果再要附加需要用变量生成,然后用exec执行。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询