
select
    *
     ,CASE
          WHEN deli_type = '内部用酒' THEN '内部用酒'
          WHEN bu_code = '0202/0223'
              THEN(CASE WHEN pl_name = '小郎酒' THEN '小郎酒事业部'
                        WHEN pl_name in ('郎牌特曲', '郎牌原浆', '新郎酒') THEN '郎牌特曲事业部'
                        WHEN pl_name in ('青花郎', '老郎酒', '藏品') THEN '青花郎事业部'
              END
              )
          ELSE  bu_name
    END AS report_bu_name  -- 报表事业部
     ,CASE
          WHEN deli_type = '内部用酒' THEN '内部用酒'
          WHEN bu_code = '0202/0223'
              THEN(CASE WHEN pl_name = '小郎酒' THEN '小郎酒川渝大区'
                        WHEN pl_name in ('郎牌特曲', '郎牌原浆', '新郎酒') THEN '郎特四川大区'
                        WHEN pl_name in ('青花郎', '老郎酒', '藏品') THEN '青花郎川渝大区'
              END
              )
          ELSE  region_name
    END AS report_region_name  -- 报表大区
from dm.v_ag_sal_deliver
WHERE 1 = 1
-- 发货单号
    ${if(len(p_deli_code) == 0,"","and deli_code = '" + p_deli_code + "'")}
-- 订单号
      ${if(len(p_order_code) == 0,"","and order_code = '" + p_order_code + "'")}
--
      ${if(p_is_src_deal== "主经销商",if(len(p_deal_name)==0,"","and deal_name in ('" + p_deal_name + "')"),if(len(p_deal_name)==0,"","and src_deal_name in ('" + p_deal_name + "')"))}
