SELECT
  RTRIM(LOCOMP) AS locomp,
  RTRIM(LOCUST) AS locust,
  RTRIM("LOINV#") AS "loinv#",
  RTRIM(LOTTYP) AS lottyp,
  CASE WHEN LOIDAT IN (DATE('0001-01-01'), DATE('9999-12-31')) THEN NULL ELSE LOIDAT END AS loidat,
  CASE WHEN LOTDAT IN (DATE('0001-01-01'), DATE('9999-12-31')) THEN NULL ELSE LOTDAT END AS lotdat,
  RTRIM(LOTRTP) AS lotrtp,
  LOAMT AS loamt,
  RTRIM(LOCURR) AS locurr,
  RTRIM("LOCHQ#") AS "lochq#",
  RTRIM(LOTRDS) AS lotrds,
  RTRIM("LOCOM#") AS "locom#",
  RTRIM(LOARAC) AS loarac,
  RTRIM(A1) AS a1,
  LOFSYR AS lofsyr,
  LOFSPR AS lofspr,
  RTRIM(A2) AS a2,
  RTRIM(LOPCUS) AS lopcus,
  CASE WHEN LOCHDT IN (DATE('0001-01-01'), DATE('9999-12-31')) THEN NULL ELSE LOCHDT END AS lochdt,
  RTRIM(LOMAJR) AS lomajr,
  RTRIM(LOMINR) AS lominr,
  RTRIM(LOTERY) AS lotery,
  RTRIM(LOCUSR) AS locusr,
  RTRIM(LOARBC) AS loarbc,
  RTRIM(LOPYBC) AS lopybc,
  LOCRID AS locrid,
  LOCUEX AS locuex,
  LOTNX AS lotnx,
  LOABTH AS loabth,
  LOCBTH AS locbth,
  LOVAMT AS lovamt
FROM LGDAT.ARTRN
WHERE LOTNX >= {lotnx}
