码迷,mamicode.com
首页 > 数据库 > 详细

sql server case when 判断为空

时间:2015-12-14 18:45:55      阅读:360      评论:0      收藏:0      [点我收藏+]

标签:

代码如下

 select
        distinct G.* 
        ,(select BUSINESS_NAME from BusinessInfo where BusinessInfo.BUSINESS_BID=G.G_BUSINESS_ID) as BUSINESS_NAME
        ,(select sum(StockGNum) from StockDetail where StockDetail.StockGID =G.G_ID) as StockGNum
        ,(select sum(StockRemovalGNum) from StockRemovalDetail where StockRemovalDetail.StockRemovalGID =G.G_ID) as StockRemovalGNum
        ,T.COMMUNITYID
        ,case when GNumber is null then 0 else DA.GNumber end as GNumber  -- 判断为空
    from
        B_GoodsInfo G left join  B_Goods_Type T on G.G_BUSINESS_ID = T.T_BUSINESS_ID left join BusinessInfo B on G.G_BUSINESS_ID = B.BUSINESS_BID
        left join (select * from  DiningCarApplyDetail where ApplyForDate = CONVERT(varchar(100), GETDATE(), 23)) DA on DA.GID=G.G_ID
    where
      T.COMMUNITYID = 43450BD834E54247A187DD0186E96240
      and B.BUSINESS_Type=001

 

sql server case when 判断为空

标签:

原文地址:http://www.cnblogs.com/nele/p/5045641.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!