langjiu-project/BI/销售业绩/销售发货明细-废弃.sql

53 lines
2.0 KiB
SQL
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

-- ======================================
-- 2024-11-21由李维调整完毕
-- ======================================
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 deli_time >= '${sStart_date}'
AND deli_time <= '${sEnd_date}'
-- 事业部
${if(len(sBu) == 0,"","and bu_code in ('" + sBu + "')")}
-- 大区
${if(len(sRegion) == 0,"","and region_code in ('" + sRegion + "')")}
-- 办事处
${if(len(sOffice) == 0,"","and office_code in ('" + sOffice + "')")}
-- 城市单元
${if(len(sCu) == 0,"","and city_unit_code in ('" + sCu + "')")}
-- 子主经销商筛选
${if(sIs_srcdeal== "主经销商",if(len(sDeal)==0,"","and deal_code in ('" + sDeal + "')"),if(len(sDeal)==0,"","and src_deal_code in ('" +sDeal + "')"))}
-- 产品
${if(len(sProd) == 0,"","and product_code in ('" + sProd + "')")}
-- 发货单号
${if(len(sDeli_code) == 0,"","and deli_code = '" + sDeli_code + "'")}
-- 订单号
${if(len(sOrder) == 0,"","and order_code = '" + sOrder + "'")}