SELECT
  KPCOMP AS kpcomp,
  KPCCYY AS kpccyy,
  KPMAXP AS kpmaxp,
  CASE WHEN KPSD01 IN (DATE('0001-01-01'), DATE('9999-12-31')) THEN NULL ELSE KPSD01 END AS kpsd01,
  CASE WHEN KPED01 IN (DATE('0001-01-01'), DATE('9999-12-31')) THEN NULL ELSE KPED01 END AS kped01,
  KPDY01 AS kpdy01,
  CASE WHEN KPSD02 IN (DATE('0001-01-01'), DATE('9999-12-31')) THEN NULL ELSE KPSD02 END AS kpsd02,
  CASE WHEN KPED02 IN (DATE('0001-01-01'), DATE('9999-12-31')) THEN NULL ELSE KPED02 END AS kped02,
  KPDY02 AS kpdy02,
  CASE WHEN KPSD03 IN (DATE('0001-01-01'), DATE('9999-12-31')) THEN NULL ELSE KPSD03 END AS kpsd03,
  CASE WHEN KPED03 IN (DATE('0001-01-01'), DATE('9999-12-31')) THEN NULL ELSE KPED03 END AS kped03,
  KPDY03 AS kpdy03,
  CASE WHEN KPSD04 IN (DATE('0001-01-01'), DATE('9999-12-31')) THEN NULL ELSE KPSD04 END AS kpsd04,
  CASE WHEN KPED04 IN (DATE('0001-01-01'), DATE('9999-12-31')) THEN NULL ELSE KPED04 END AS kped04,
  KPDY04 AS kpdy04,
  CASE WHEN KPSD05 IN (DATE('0001-01-01'), DATE('9999-12-31')) THEN NULL ELSE KPSD05 END AS kpsd05,
  CASE WHEN KPED05 IN (DATE('0001-01-01'), DATE('9999-12-31')) THEN NULL ELSE KPED05 END AS kped05,
  KPDY05 AS kpdy05,
  CASE WHEN KPSD06 IN (DATE('0001-01-01'), DATE('9999-12-31')) THEN NULL ELSE KPSD06 END AS kpsd06,
  CASE WHEN KPED06 IN (DATE('0001-01-01'), DATE('9999-12-31')) THEN NULL ELSE KPED06 END AS kped06,
  KPDY06 AS kpdy06,
  CASE WHEN KPSD07 IN (DATE('0001-01-01'), DATE('9999-12-31')) THEN NULL ELSE KPSD07 END AS kpsd07,
  CASE WHEN KPED07 IN (DATE('0001-01-01'), DATE('9999-12-31')) THEN NULL ELSE KPED07 END AS kped07,
  KPDY07 AS kpdy07,
  CASE WHEN KPSD08 IN (DATE('0001-01-01'), DATE('9999-12-31')) THEN NULL ELSE KPSD08 END AS kpsd08,
  CASE WHEN KPED08 IN (DATE('0001-01-01'), DATE('9999-12-31')) THEN NULL ELSE KPED08 END AS kped08,
  KPDY08 AS kpdy08,
  CASE WHEN KPSD09 IN (DATE('0001-01-01'), DATE('9999-12-31')) THEN NULL ELSE KPSD09 END AS kpsd09,
  CASE WHEN KPED09 IN (DATE('0001-01-01'), DATE('9999-12-31')) THEN NULL ELSE KPED09 END AS kped09,
  KPDY09 AS kpdy09,
  CASE WHEN KPSD10 IN (DATE('0001-01-01'), DATE('9999-12-31')) THEN NULL ELSE KPSD10 END AS kpsd10,
  CASE WHEN KPED10 IN (DATE('0001-01-01'), DATE('9999-12-31')) THEN NULL ELSE KPED10 END AS kped10,
  KPDY10 AS kpdy10,
  CASE WHEN KPSD11 IN (DATE('0001-01-01'), DATE('9999-12-31')) THEN NULL ELSE KPSD11 END AS kpsd11,
  CASE WHEN KPED11 IN (DATE('0001-01-01'), DATE('9999-12-31')) THEN NULL ELSE KPED11 END AS kped11,
  KPDY11 AS kpdy11,
  CASE WHEN KPSD12 IN (DATE('0001-01-01'), DATE('9999-12-31')) THEN NULL ELSE KPSD12 END AS kpsd12,
  CASE WHEN KPED12 IN (DATE('0001-01-01'), DATE('9999-12-31')) THEN NULL ELSE KPED12 END AS kped12,
  KPDY12 AS kpdy12,
  CASE WHEN KPSD13 IN (DATE('0001-01-01'), DATE('9999-12-31')) THEN NULL ELSE KPSD13 END AS kpsd13,
  CASE WHEN KPED13 IN (DATE('0001-01-01'), DATE('9999-12-31')) THEN NULL ELSE KPED13 END AS kped13,
  KPDY13 AS kpdy13,
  CASE WHEN KPSD14 IN (DATE('0001-01-01'), DATE('9999-12-31')) THEN NULL ELSE KPSD14 END AS kpsd14,
  CASE WHEN KPED14 IN (DATE('0001-01-01'), DATE('9999-12-31')) THEN NULL ELSE KPED14 END AS kped14,
  KPDY14 AS kpdy14,
  CASE WHEN KPSD15 IN (DATE('0001-01-01'), DATE('9999-12-31')) THEN NULL ELSE KPSD15 END AS kpsd15,
  CASE WHEN KPED15 IN (DATE('0001-01-01'), DATE('9999-12-31')) THEN NULL ELSE KPED15 END AS kped15,
  KPDY15 AS kpdy15
FROM LGDAT.GLDATE
