select aa.bh ,aa.na,isnull(bb.much,0),case when isnull(bb.much,0)<aa.down then aa.down-isnull(bb.much,0) else 0 end as down,case when isnull(bb.much,0)>aa.up then isnull(bb.much,0)-aa.up else 0 end as up
from prod.dbo.aa aa left join depot.dbo.bb bb on aa.bj=bb.bh

解决方案 »

  1.   

    Select aa.bh,aa.na,bb.much,CASE WHEN aa.up<bb.much then bb.much-aa.up ELSE 0 END AS 超上限,CASE WHEN aa.down>bb.much then aa.down-bb.much ELSE 0 END as 越下限
    From prod..aa as aa INNER JOIN depot..bb as bb
    ON aa.bh=bb.bh
      

  2.   

    这么快啊,可现在公司关门了啊,明天我就去试,谢谢 Yang_(扬帆破浪) 和
     N_Chow(一劍飄香) (  )!!!!谢谢!