SQLServer Case when 嵌套

select top 10000 b.Code,b.Name,b.EffDateShortControl 标识,b.EffDateControlStart 开始时间,
b.EffDateControlEnd 结束时间,b.EffDateShortDays 缩短日期,
c.InputDate 入库日期,a.EffDate 入库原始有效日期,
 CASE isnull(EffDateShortControl,0)
                          when 0
        then  a.EffDate
                          when 1
          then 
              case when  c.InputDate>=b.EffDateControlStart and c.InputDate<=b.EffDateControlEnd
                 then a.EffDate-b.EffDateShortDays
           else case when  c.InputDate>b.EffDateControlEnd or c.InputDate<b.EffDateControlStart
          then  a.EffDate
          end
       end 
                        END AS 缩短日期--如果不启用质检就直接可用
 from W_doc_receiving_master c inner join  W_doc_receiving_detail a
 on c.ID = a.MasterId
  left join W_inf_product b on  a.ProdId=b.Id

posted @ 2013-08-27 15:13  滴水藏海  阅读(5263)  评论(0编辑  收藏  举报