set @insertsql='insert into #indextable (nid) select id from pur where id!='''''+@strSql4begin
   set @strSql = 'select depno,pono,P.id from pur P,#indextable T'
  set @strSql = @strSql + ' where P.id=T.nid '+@strSql4+'and T.id between cast('+str(@PageLowerBound)+' as int)+1 and cast('+ str(@PageUpperBound)+' as int) order by T.id'
end 上面的2个存储语句是从一个表pur里取数据,现在假如我要在2个表里取数据,比如还要在另一个表pur2里取字段qty,id,vendor,那么该怎么改呀(在原有的基础上改)?
2个表的关联键字段是dga01c

解决方案 »

  1.   

    begin
       set @strSql = 'select depno, pono,P.id, p2.qty, p2.id, p2.vendor from pur P,#indextable T, pur2 p2'
       set @strSql = @strSql + ' where P.id=T.nid and p.dg01c = p2.dg01c '+@strSql4+'and T.id between cast('+str(@PageLowerBound)+
    ' as int)+1 and cast('+ str(@PageUpperBound)+' as int) order by T.id'
    end
      

  2.   

    基本原则知道了就容易了
    如一个表select col1,col2 from tableA
    两个表就是select col1,col2 from tableA,tableB 
    多个表就在from后增加
    但注意select 后需指定表对应字段如,tableA.col1,tableB.col3等
    强烈建议你看一下数据库方面的基本知识
      

  3.   

    set @insertsql='insert into #indextable (nid) select p2.id from b1 P,b2 p2 where p2.id!='''' and P.pono=p2.pono'+@strSql4begin
       set @strSql = 'select  P.zd1,P.zd2,P.pono,p2.zd11,p2.zd22,p2.id from b1 P,#indextable T,b2 p2'
      set @strSql = @strSql + ' where P.pono=p2.pono and p2.id=T.nid '+@strSql4+'and T.id between cast('+str(@PageLowerBound)+' as int)+1 and cast('+ str(@PageUpperBound)+' as int) order by T.id'
     end 这样写为什么最后一页的数据不能显示出来?
      

  4.   

    set @insertsql='insert into #indextable (nid) select p2.id from b1 P,b2 p2 where p2.id!='''' and P.pono=p2.pono'+@strSql4begin
       set @strSql = 'select  P.zd1,P.zd2,P.pono,p2.pono,p2.zd11,p2.zd22,p2.id from b1 P,#indextable T,b2 p2'
      set @strSql = @strSql + ' where P.pono=p2.pono and p2.id=T.nid '+@strSql4+'and T.id between cast('+str(@PageLowerBound)+' as int)+1 and cast('+ str(@PageUpperBound)+' as int) order by T.id'
     end