-- JdeUser Query (Full only - no filtered variant)
-- Source: JDESTAGE.F0101_VIEW, JDESTAGE.F0092_VIEW
-- Destination: JdeUser
-- Schedule: Mass/Daily/Hourly
-- Note: Same query used for both full and incremental (filter params passed but not used)

WITH USER_CTE AS (
  SELECT ab.ADDRESSNUMBER_ABAN8 AS AddressNumber,
         TRIM(pro.USERID_ULUSER) AS UserID,
         TRIM(ab.NAMEALPHA_ABALPH) AS FullName,
         ab.DATEUPDATED_ABUPMJ AS DateUpdated,
         ab.TIMELASTUPDATED_ABUPMT AS TimeUpdated,
         ROW_NUMBER() OVER (PARTITION BY ab.ADDRESSNUMBER_ABAN8 ORDER BY ab.DATEUPDATED_ABUPMJ DESC, ab.TIMELASTUPDATED_ABUPMT DESC) RN
   FROM  JDESTAGE.F0101_VIEW ab LEFT OUTER JOIN
         JDESTAGE.F0092_VIEW pro ON (ab.ADDRESSNUMBER_ABAN8 = pro.ADDRESSNUMBER_ULAN8)
   WHERE ab.ADDRESSTYPEEMPLOYEE_ABATE = 'Y'
)
SELECT AddressNumber,
       UserID,
       FullName,
       DateUpdated,
       TimeUpdated
  FROM USER_CTE
 WHERE RN = 1
