在存储过程中,如何实现按条件下移的过程。
比如:
第一条:select * from db1 where aa=1 and bb=2
然后在这个范围内查询第二条语句:
    selcet db2.aa,db3.bb  from db2,db3 where 
        db2.cc in (selcet id  from db1 where bb=2)
        and  .....                                  不知道我表述的各位高手可否看懂?
补充:就是类似于程序中的条件判断,在第一个条件范围内,加载
其他条件!

解决方案 »

  1.   

    呵呵
    那就是用
    if EXISTS(select * from db1 where aa=1 and bb=2 )
    begin
            selcet db2.aa,db3.bb  from db2,db3 where
            db2.cc in (selcet id  from db1 where bb=2)
            and  ..... 
    end
    else if EXISTS(select * from db1 where aa=1 and bb=2 )
    begin
            selcet db2.aa,db3.bb  from db2,db3 where
            db2.cc in (selcet id  from db1 where bb=2)
            and  ..... 
    end
    .........
    不知是不是你要的结果
      

  2.   

    declare ct=0;
    select @ct=count * from db1 where aa=1 and bb=2;
    if @ct>0
      

  3.   


    declare @count=0; 
    select @count=count (*) from db1 where aa=1 and bb=2; 
    if @ct>0
       selcet db2.aa,db3.bb  from db2,db3 where 
            db2.cc in (selcet id  from db1 where bb=2) 
            and  ..... 
      

  4.   

     selcet db2.aa,db3.bb  from db2,db3 where 
            db2.cc in (selcet id  from db1 where bb=2) 
            and  .....  
    if exists  (select db1.id from db1,db2 where db1.id=db2.cc and db1.bb=2)
    begin
    ...
    end