SELECT a.*, b.f_desc,c.dd  FROM a
    case when b.id<>null then JOIN  b ON a.f_bid= b.f_id else ''
    case when c.id<>null then JOIN  c ON a.f_cid= c.f_id else ''
一个错误的sql语句,不知道该如何改,请过路的高手费费心,谢谢

解决方案 »

  1.   

    SELECT a.*, b.f_desc,c.dd  FROM a 
        case when b.id <>null then JOIN  b ON a.f_bid= b.f_id else '' 
        case when c.id <>null then JOIN  c ON a.f_cid= c.f_id else '' 
    一个错误的sql语句,不知道该如何改,请过路的高手费费心,谢谢SELECT a.*, b.f_desc,c.dd  FROM a join b 
      on a.f_bid on b.f_id and b.id is not null
      join c on a.f_cid=c.f_id and c.id is not null
      

  2.   

    稍微修改了下SELECT a.*, b.f_desc,c.dd  
    FROM A , B, C 
    WHERE A.F_BID = B.F_ID AND A.F_CID = C.F_ID 
          AND ISNULL(B.ID,0) >0 AND ISNULL(C.ID,0) > 0
      

  3.   

    SELECT a.*, b.f_desc,c.dd  FROM a 
        case when b.id <>null then JOIN  b ON a.f_bid= b.f_id else '' 
        case when c.id <>null then JOIN  c ON a.f_cid= c.f_id else '' 
    如果b.id我就不想在连接b表了;如果c.id我就不想在连接c表了...
      

  4.   


    <> 換成 is not 
      

  5.   


    SELECT a.*, 
    (select max(b.f_desc) from b where a.f_bid= b.f_id and b.id is not null),
    (select max(c.dd ) from c where a.f_bid= c.f_id and c.id is not null)
    FROM a 
    --功力浅薄,抛砖引玉
      

  6.   

    一般我们不用<>null 用is not null
      

  7.   

    hi,汗颜,弄错了,应该是left join