-- 转卡开单品项明细 yjsj 为空导致品项开单报表按时间筛选查不到
-- 用开单主表 kdrq 回填（与代码 COALESCE(yjsj, kdrq) 口径一致）

-- 预览
SELECT px.F_Id, px.glkdbh, px.yjsj, k.kdrq, k.fkfs, k.sfyj
FROM lq_kd_pxmx px
INNER JOIN lq_kd_kdjlb k ON px.glkdbh = k.F_Id
WHERE px.yjsj IS NULL
  AND k.kdrq IS NOT NULL
  AND px.F_IsEffective = 1
  AND k.F_IsEffective = 1
  AND k.fkfs = '转卡'
LIMIT 50;

-- 修复
UPDATE lq_kd_pxmx px
INNER JOIN lq_kd_kdjlb k ON px.glkdbh = k.F_Id
SET px.yjsj = k.kdrq
WHERE px.yjsj IS NULL
  AND k.kdrq IS NOT NULL
  AND px.F_IsEffective = 1
  AND k.F_IsEffective = 1
  AND k.fkfs = '转卡';
