select * from openquery (sis, '
select sfrstcr_term_code, sfrstcr_crn, spriden_first_name, spriden_last_name, spriden_id, lower(wormoth_login_id) loginid
from sfrstcr
inner join spriden on sfrstcr_pidm = spriden_pidm
inner join wormoth on sfrstcr_pidm = wormoth_pidm
where sfrstcr_term_code = 201903
and sfrstcr_crn = 64261
and sfrstcr_rsts_code in (''RE'', ''RW'')
and SPRIDEN_CHANGE_IND is null
and wormoth_acct_type = ''Z''
and wormoth_acct_status = ''A''
and wormoth_activity_date = ( select max(wormoth_activity_date ) from wormoth iw where iw.WORMOTH_PIDM = wormoth.wormoth_pidm and iw.wormoth_acct_type = ''Z'' and iw.wormoth_acct_status = ''A'' )
')
select * from openquery (sis, ' select sfrstcr_term_code, sfrstcr_crn, spriden_first_name, spriden_last_name, spriden_id, lower(wormoth_login_id) loginid from sfrstcr inner join spriden on sfrstcr_pidm = spriden_pidm inner join wormoth on sfrstcr_pidm = wormoth_pidm where sfrstcr_term_code = 201903 and sfrstcr_crn = 64261 and sfrstcr_rsts_code in (''RE'', ''RW'') and SPRIDEN_CHANGE_IND is null and wormoth_acct_type = ''Z'' and wormoth_acct_status = ''A'' and wormoth_activity_date = ( select max(wormoth_activity_date ) from wormoth iw where iw.WORMOTH_PIDM = wormoth.wormoth_pidm and iw.wormoth_acct_type = ''Z'' and iw.wormoth_acct_status = ''A'' ) ')