SELECT
  "FEBOL#" AS "febol#",
  RTRIM(FEBTYP) AS febtyp,
  CASE WHEN FECDAT IN (DATE('0001-01-01'), DATE('9999-12-31')) THEN NULL ELSE FECDAT END AS fecdat,
  RTRIM(FEPIND) AS fepind,
  RTRIM(FESIND) AS fesind,
  RTRIM("FEBCS#") AS "febcs#",
  RTRIM("FESCS#") AS "fescs#",
  RTRIM(FESVND) AS fesvnd,
  RTRIM(FERVND) AS fervnd,
  RTRIM(FEBNME) AS febnme,
  RTRIM(FEBPTC) AS febptc,
  RTRIM(FEATTN) AS feattn,
  RTRIM(FESNME) AS fesnme,
  RTRIM(FESAD1) AS fesad1,
  RTRIM(FESAD2) AS fesad2,
  RTRIM(FESAD3) AS fesad3,
  RTRIM(FESAD4) AS fesad4,
  RTRIM(FESAD5) AS fesad5,
  RTRIM(FESAD6) AS fesad6,
  RTRIM(FESAD7) AS fesad7,
  RTRIM(FESAD8) AS fesad8,
  RTRIM(FESAD9) AS fesad9,
  RTRIM(FESAD10) AS fesad10,
  RTRIM(FESPTC) AS fesptc,
  RTRIM(FESCTY) AS fescty,
  RTRIM(FESPOV) AS fespov,
  RTRIM(FESCRY) AS fescry,
  CASE WHEN FESDAT IN (DATE('0001-01-01'), DATE('9999-12-31')) THEN NULL ELSE FESDAT END AS fesdat,
  RTRIM(FESVIA) AS fesvia,
  RTRIM(FETKID) AS fetkid,
  FENCTN AS fenctn,
  FENETW AS fenetw,
  FEGROW AS fegrow,
  FETARW AS fetarw,
  RTRIM(FEWTUN) AS fewtun,
  RTRIM(FEDOCD) AS fedocd,
  RTRIM(FEFTCD) AS feftcd,
  "FEORD#" AS "feord#",
  RTRIM(FESTKL) AS festkl,
  FEFTAM AS feftam,
  RTRIM(FEFOB) AS fefob,
  RTRIM(FECARC) AS fecarc,
  RTRIM(FESERC) AS feserc,
  FESTME AS festme,
  RTRIM(FEJITF) AS fejitf,
  RTRIM("FESID#") AS "fesid#",
  RTRIM(FETRPT) AS fetrpt,
  RTRIM(FEBID) AS febid,
  RTRIM(FESID) AS fesid,
  RTRIM(FESFID) AS fesfid,
  RTRIM(FEPLNT) AS feplnt,
  RTRIM(FEITMC) AS feitmc,
  RTRIM(FESUPP) AS fesupp,
  RTRIM(FEULTD) AS feultd,
  CASE WHEN FEEDAT IN (DATE('0001-01-01'), DATE('9999-12-31')) THEN NULL ELSE FEEDAT END AS feedat,
  FEETIM AS feetim,
  CASE WHEN FEADAT IN (DATE('0001-01-01'), DATE('9999-12-31')) THEN NULL ELSE FEADAT END AS feadat,
  FEATIM AS featim,
  RTRIM(FETRNM) AS fetrnm,
  RTRIM(FERTEG) AS ferteg,
  RTRIM(FEPLPT) AS feplpt,
  RTRIM(FEPLOC) AS feploc,
  RTRIM(FEEQPD) AS feeqpd,
  RTRIM(FEEQPI) AS feeqpi,
  RTRIM(FEEQID) AS feeqid,
  FEMBOL AS fembol,
  RTRIM(FEPSLP) AS fepslp,
  RTRIM(FEFRTB) AS fefrtb,
  RTRIM(FEAIRB) AS feairb,
  RTRIM(FETSPR) AS fetspr,
  RTRIM(FEETRR) AS feetrr,
  RTRIM(FEEXTR) AS feextr,
  RTRIM(FEAETC) AS feaetc,
  RTRIM(FEMTHP) AS femthp,
  RTRIM(FETRNT) AS fetrnt,
  RTRIM(FETRLQ) AS fetrlq,
  RTRIM(FECCT) AS fecct,
  RTRIM(FECCDE) AS feccde,
  RTRIM(FESASN) AS fesasn,
  RTRIM(FESNTF) AS fesntf,
  RTRIM(FESTS) AS fests,
  RTRIM(FEXMOD) AS fexmod,
  RTRIM(FEATYP) AS featyp,
  RTRIM(FEFLD1) AS fefld1,
  RTRIM(FEFLD2) AS fefld2,
  RTRIM(FEFLD3) AS fefld3,
  RTRIM(FEFLD4) AS fefld4,
  RTRIM(FEFLD5) AS fefld5,
  RTRIM(FEFLD6) AS fefld6,
  RTRIM(FEMANW) AS femanw,
  RTRIM(FES204) AS fes204,
  RTRIM(FEBTRP) AS febtrp,
  RTRIM(FEBSTS) AS febsts,
  RTRIM(FEBACK) AS feback,
  RTRIM(FEBSET) AS febset,
  RTRIM(FEBMOD) AS febmod,
  FESKDQ AS feskdq,
  RTRIM(FESKDT) AS feskdt,
  FELOSQ AS felosq,
  RTRIM(FELOST) AS felost,
  RTRIM(FECRCM) AS fecrcm,
  RTRIM(FEUSE) AS feuse,
  RTRIM(FESLCS) AS feslcs,
  RTRIM(FECRTY) AS fecrty,
  RTRIM(FECRDT) AS fecrdt,
  RTRIM("FECRD#") AS "fecrd#",
  RTRIM(FEEXPR) AS feexpr,
  RTRIM(FEHODR) AS fehodr,
  FECRNM AS fecrnm,
  RTRIM(FESHBF) AS feshbf,
  RTRIM(FECLEN) AS feclen,
  RTRIM(FEPLTC) AS fepltc,
  RTRIM(FEFUT1) AS fefut1,
  RTRIM(FEFUT2) AS fefut2,
  RTRIM(FEFUT3) AS fefut3,
  RTRIM(FEFUT4) AS fefut4,
  RTRIM(FEFUT5) AS fefut5,
  RTRIM(FEFUT6) AS fefut6,
  RTRIM(FEFUT7) AS fefut7,
  RTRIM(FEFUT8) AS fefut8,
  RTRIM(FEFUT9) AS fefut9,
  RTRIM(FEFUTA) AS fefuta,
  RTRIM(FEFUTB) AS fefutb,
  FEFUTC AS fefutc,
  RTRIM(FEFUTD) AS fefutd,
  RTRIM(FEFUTE) AS fefute,
  RTRIM(FEFUTF) AS fefutf,
  RTRIM(FEFUTG) AS fefutg,
  RTRIM(FELDTY) AS feldty,
  RTRIM(FETKST) AS fetkst,
  RTRIM(FERTS) AS ferts,
  RTRIM(FEFUTH) AS fefuth,
  RTRIM(FEFUTI) AS fefuti,
  RTRIM(FEFUTJ) AS fefutj,
  RTRIM(FEFUTK) AS fefutk,
  RTRIM(FEFUTL) AS fefutl,
  RTRIM(FEFUTM) AS fefutm,
  RTRIM(FEFUTN) AS fefutn,
  RTRIM(FEFUTO) AS fefuto,
  RTRIM(FEFUTP) AS fefutp,
  RTRIM(FEFUTQ) AS fefutq,
  RTRIM(FEFUTR) AS fefutr,
  RTRIM(FEFUTS) AS fefuts,
  RTRIM(FEFUTT) AS fefutt,
  RTRIM(FEFUTU) AS fefutu,
  RTRIM(FEFUTV) AS fefutv,
  RTRIM(FEFUTW) AS fefutw,
  FEFUTX AS fefutx,
  FEFUTY AS fefuty,
  FEFUTZ AS fefutz,
  FESCNC AS fescnc,
  CASE WHEN FEDDAT IN (DATE('0001-01-01'), DATE('9999-12-31')) THEN NULL ELSE FEDDAT END AS feddat,
  FEDTME AS fedtme,
  RTRIM(FEDCMT) AS fedcmt,
  RTRIM("FEMBL#") AS "fembl#",
  RTRIM(FEATMZ) AS featmz,
  RTRIM(FEETMZ) AS feetmz,
  RTRIM(FESTMZ) AS festmz,
  RTRIM(FECTMZ) AS fectmz,
  RTRIM(FEPSTS) AS fepsts,
  RTRIM(FETENT) AS fetent,
  RTRIM(FEPQN) AS fepqn,
  RTRIM(FETAMT) AS fetamt,
  RTRIM(FEIBN) AS feibn,
  RTRIM(FESTTP) AS festtp,
  RTRIM(FESTCN) AS festcn,
  RTRIM(FEEXPDT) AS feexpdt,
  RTRIM(FEDLTB) AS fedltb,
  RTRIM(FEPUSR) AS fepusr,
  CASE WHEN FEPDAT IN (DATE('0001-01-01'), DATE('9999-12-31')) THEN NULL ELSE FEPDAT END AS fepdat,
  FEPTIM AS feptim,
  RTRIM(FEFUT10) AS fefut10,
  RTRIM(FEFUT11) AS fefut11,
  RTRIM(FEFUT12) AS fefut12,
  RTRIM(FEFUT13) AS fefut13,
  RTRIM(FEFUT14) AS fefut14,
  RTRIM(FEFUT15) AS fefut15,
  RTRIM(FEFUT16) AS fefut16,
  RTRIM(FEFUT17) AS fefut17,
  FEFUT18 AS fefut18,
  FEFUT19 AS fefut19,
  FEFUT20 AS fefut20
FROM LGDAT.BOLH
WHERE
      (fecdat BETWEEN '{bolh_wm}' AND CURRENT_DATE)          -- new + recently-created edits
   OR (fepdat BETWEEN '{bolh_wm}' AND CURRENT_DATE)          -- unposted → posted flip
   OR (feddat BETWEEN '{bolh_wm}' AND CURRENT_DATE)          -- cancellations (Date Deleted)
   OR (fepdat IS NULL AND feddat IS NULL                     -- live pending tail, not cancelled
       AND fecdat >= CURRENT_DATE - 90 DAYS)                      --   ~1k rows
