Files
Misaka_Company 4dc563cdd9 Initial commit
2026-07-30 14:17:18 +08:00

38 lines
1.8 KiB
SQL
Raw Permalink 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.
-- 装箱单:按 排产号 + 箱号 取箱内明细,并双表 LEFT JOIN 取产品信息。
-- 参数paichan_no (str, 排产号) / box_no (int, 箱号)
-- 注load_sql 会剥离整行 -- 注释,故注释里可自由书写中文。
--
-- 数据来源:
-- CargoTrace.finished_goods_box 箱头(排产号 + 箱号 + 装箱时间)
-- CargoTrace.finished_goods_box_item 箱内明细(总排号 + 装入数量)
-- productionContractData.26年压力表合同数据 / 26年温度计合同数据 产品信息
--
-- 产品信息双表取值:同一总排号只命中压力表或温度计其中一张表。
-- 用双 LEFT JOIN + COALESCE 取产品字段避免前缀路由出错26BW 不会被 26B% 误匹配)。
--
-- 字段说明(注意历史遗留命名):
-- product_name取自合同表 [客户名称] 字段,但实际存的是产品名称(历史笔误,系统已用,不改字段名)
-- weihao位号多数订单为空有则显示、无则留白
-- remark备注
SELECT b.paichan_no,
b.box_no,
b.created_at,
i.zongpai_no,
i.quantity AS box_qty,
COALESCE(p.[], t.[]) AS product_name,
COALESCE(p.[], t.[]) AS model,
COALESCE(p.[], t.[]) AS range_,
COALESCE(p.[], t.[]) AS weihao,
COALESCE(p.[], t.[]) AS remark,
COALESCE(p.[], t.[]) AS order_no
FROM CargoTrace.finished_goods_box b
JOIN CargoTrace.finished_goods_box_item i
ON i.box_id = b.id
LEFT JOIN [productionContractData].[26] p
ON p.[] = i.zongpai_no
LEFT JOIN [productionContractData].[26] t
ON t.[] = i.zongpai_no
WHERE b.paichan_no = :paichan_no
AND b.box_no = :box_no
ORDER BY i.id;