sybase执行存储过程报错

yan_min1990 2013-10-09 07:08:17
create procedure SPLITEPAGE @qry varchar(16384),@ipage int, @num int as
begin
declare @maxpages int
declare @rcount int
declare @execsql varchar(16384)

if @ipage>=100
select @maxpages=ceiling(count(*)/@num) from TB_DATA_DICTIONARY
else
select @maxpages=100000
if @ipage<=@maxpages/2
begin
select @rcount=@ipage*@num
set rowcount @rcount
set @execsql = stuff(@qry,charindex('select',@qry),6,'select sybid=identity(12),')
set @execsql = stuff(@execsql, charindex('from',@execsql),4,'into #temptable1 from')
set @execsql = @execsql || ' select * from #temptable1 where sybid>' || convert(varchar,(@ipage-1)*@num) || ' and sybid <= ' || convert(varchar,@ipage*@num)
execute (@execsql)

end else
begin
select @rcount=(@maxpages-@ipage+1)*@num
set rowcount @rcount
set @execsql = stuff(@qry,charindex('select',@qry),6,'select sybid=identity(12),')
set @execsql = stuff(@execsql, charindex('from',@execsql),4,'into #temptable1 from')
set @execsql = @execsql || ' order by sybid desc'
set @execsql = @execsql || ' select * from #temptable1 where sybid > ' || convert(varchar,(@maxpages-@ipage)*@num) || ' and sybid <= ' || convert(varchar,(@maxpages-@ipage+1)*@num)
execute (@execsql)
end
end

exec SPLITEPAGE 'select * from TB_SYS_ADMIN ',1,1


报如下错误
18:53:34.234 DBMS RKDLNTTS4GUB6UZ -- Number (156) Severity (15) State (2) Server (RKDLNTTS4GUB6UZ) Incorrect syntax near the keyword 'into'.
...全文
691 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
ocean_helen 2013-10-24
  • 打赏
  • 举报
回复
我删了 if @ipage>=100 select @maxpages=ceiling(count(*)/@num) from TB_DATA_DICTIONARY else 在每个@execsql后加了select打印,可以执行。。。不知道楼主哪里出问题,打印出来看看? 1> exec SPLITEPAGE 'select * from t1',1,1 2> go 1:select sybid=identity(12), * from t1 (1 row affected) 2:select sybid=identity(12), * into #temptable1 from t1 (1 row affected) 3:select sybid=identity(12), * into #temptable1 from t1 select * from #temptable1 where sybid>0 and sybid <= 1 (1 row affected) sybid name --------------- -------------------- 1 a (1 row affected)
iihero 2013-10-15
  • 打赏
  • 举报
回复
中间加一些调试信息看看, 用select之类的把它们打出来。
baiynije 2013-10-15
  • 打赏
  • 举报
回复
你可以在执行execute之前把变量@execsql显示出来看看哪里组的不对。

2,596

社区成员

发帖
与我相关
我的任务
社区描述
Sybase相关技术讨论区
社区管理员
  • Sybase社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧