SELECT * FROM OPENQUERY(GPSERVER, '
SELECT
  [SOPTYPE] AS [soptype],
  RTRIM([SOPNUMBE]) AS [sopnumbe],
  [ORIGTYPE] AS [origtype],
  RTRIM([ORIGNUMB]) AS [orignumb],
  RTRIM([DOCID]) AS [docid],
  [DOCDATE] AS [docdate],
  [GLPOSTDT] AS [glpostdt],
  [QUOTEDAT] AS [quotedat],
  [QUOEXPDA] AS [quoexpda],
  [ORDRDATE] AS [ordrdate],
  [INVODATE] AS [invodate],
  [BACKDATE] AS [backdate],
  [RETUDATE] AS [retudate],
  [ReqShipDate] AS [reqshipdate],
  [FUFILDAT] AS [fufildat],
  [ACTLSHIP] AS [actlship],
  [DISCDATE] AS [discdate],
  [DUEDATE] AS [duedate],
  [REPTING] AS [repting],
  [TRXFREQU] AS [trxfrequ],
  [TIMEREPD] AS [timerepd],
  [TIMETREP] AS [timetrep],
  [DYSTINCR] AS [dystincr],
  [DTLSTREP] AS [dtlstrep],
  RTRIM([DSTBTCH1]) AS [dstbtch1],
  RTRIM([DSTBTCH2]) AS [dstbtch2],
  RTRIM([USDOCID1]) AS [usdocid1],
  RTRIM([USDOCID2]) AS [usdocid2],
  [DISCFRGT] AS [discfrgt],
  [ORDAVFRT] AS [ordavfrt],
  [DISCMISC] AS [discmisc],
  [ORDAVMSC] AS [ordavmsc],
  [DISAVAMT] AS [disavamt],
  [ORDAVAMT] AS [ordavamt],
  [DISCRTND] AS [discrtnd],
  [ORDISRTD] AS [ordisrtd],
  [DISTKNAM] AS [distknam],
  [ORDISTKN] AS [ordistkn],
  [DSCPCTAM] AS [dscpctam],
  [DSCDLRAM] AS [dscdlram],
  [ORDDLRAT] AS [orddlrat],
  [DISAVTKN] AS [disavtkn],
  [ORDATKN] AS [ordatkn],
  RTRIM([PYMTRMID]) AS [pymtrmid],
  RTRIM([PRCLEVEL]) AS [prclevel],
  RTRIM([LOCNCODE]) AS [locncode],
  RTRIM([BCHSOURC]) AS [bchsourc],
  RTRIM([BACHNUMB]) AS [bachnumb],
  RTRIM([CUSTNMBR]) AS [custnmbr],
  RTRIM([CUSTNAME]) AS [custname],
  RTRIM([CSTPONBR]) AS [cstponbr],
  [PROSPECT] AS [prospect],
  [MSTRNUMB] AS [mstrnumb],
  RTRIM([PCKSLPNO]) AS [pckslpno],
  RTRIM([PICTICNU]) AS [picticnu],
  [MRKDNAMT] AS [mrkdnamt],
  [ORMRKDAM] AS [ormrkdam],
  RTRIM([PRBTADCD]) AS [prbtadcd],
  RTRIM([PRSTADCD]) AS [prstadcd],
  RTRIM([CNTCPRSN]) AS [cntcprsn],
  RTRIM([ShipToName]) AS [shiptoname],
  RTRIM([ADDRESS1]) AS [address1],
  RTRIM([ADDRESS2]) AS [address2],
  RTRIM([ADDRESS3]) AS [address3],
  RTRIM([CITY]) AS [city],
  RTRIM([STATE]) AS [state],
  RTRIM([ZIPCODE]) AS [zipcode],
  RTRIM([CCode]) AS [ccode],
  RTRIM([COUNTRY]) AS [country],
  RTRIM([PHNUMBR1]) AS [phnumbr1],
  RTRIM([PHNUMBR2]) AS [phnumbr2],
  RTRIM([PHONE3]) AS [phone3],
  RTRIM([FAXNUMBR]) AS [faxnumbr],
  [COMAPPTO] AS [comappto],
  [COMMAMNT] AS [commamnt],
  [OCOMMAMT] AS [ocommamt],
  [CMMSLAMT] AS [cmmslamt],
  [ORCOSAMT] AS [orcosamt],
  [NCOMAMNT] AS [ncomamnt],
  [ORNCMAMT] AS [orncmamt],
  RTRIM([SHIPMTHD]) AS [shipmthd],
  [TRDISAMT] AS [trdisamt],
  [ORTDISAM] AS [ortdisam],
  [TRDISPCT] AS [trdispct],
  [SUBTOTAL] AS [subtotal],
  [ORSUBTOT] AS [orsubtot],
  [REMSUBTO] AS [remsubto],
  [OREMSUBT] AS [oremsubt],
  [EXTDCOST] AS [extdcost],
  [OREXTCST] AS [orextcst],
  [FRTAMNT] AS [frtamnt],
  [ORFRTAMT] AS [orfrtamt],
  [MISCAMNT] AS [miscamnt],
  [ORMISCAMT] AS [ormiscamt],
  [TXENGCLD] AS [txengcld],
  RTRIM([TAXEXMT1]) AS [taxexmt1],
  RTRIM([TAXEXMT2]) AS [taxexmt2],
  RTRIM([TXRGNNUM]) AS [txrgnnum],
  RTRIM([TAXSCHID]) AS [taxschid],
  [TXSCHSRC] AS [txschsrc],
  [BSIVCTTL] AS [bsivcttl],
  RTRIM([FRTSCHID]) AS [frtschid],
  [FRTTXAMT] AS [frttxamt],
  [ORFRTTAX] AS [orfrttax],
  [FRGTTXBL] AS [frgttxbl],
  RTRIM([MSCSCHID]) AS [mscschid],
  [MSCTXAMT] AS [msctxamt],
  [ORMSCTAX] AS [ormsctax],
  [MISCTXBL] AS [misctxbl],
  [BKTFRTAM] AS [bktfrtam],
  [ORBKTFRT] AS [orbktfrt],
  [BKTMSCAM] AS [bktmscam],
  [ORBKTMSC] AS [orbktmsc],
  [BCKTXAMT] AS [bcktxamt],
  [OBTAXAMT] AS [obtaxamt],
  [TXBTXAMT] AS [txbtxamt],
  [OTAXTAMT] AS [otaxtamt],
  [TAXAMNT] AS [taxamnt],
  [ORTAXAMT] AS [ortaxamt],
  [ECTRX] AS [ectrx],
  [DOCAMNT] AS [docamnt],
  [ORDOCAMT] AS [ordocamt],
  [PYMTRCVD] AS [pymtrcvd],
  [ORPMTRVD] AS [orpmtrvd],
  [DEPRECVD] AS [deprecvd],
  [ORDEPRVD] AS [ordeprvd],
  [CODAMNT] AS [codamnt],
  [ORCODAMT] AS [orcodamt],
  [ACCTAMNT] AS [acctamnt],
  [ORACTAMT] AS [oractamt],
  RTRIM([SALSTERR]) AS [salsterr],
  RTRIM([SLPRSNID]) AS [slprsnid],
  RTRIM([UPSZONE]) AS [upszone],
  [TIMESPRT] AS [timesprt],
  [PSTGSTUS] AS [pstgstus],
  [VOIDSTTS] AS [voidstts],
  [ALLOCABY] AS [allocaby],
  [NOTEINDX] AS [noteindx],
  RTRIM([CURNCYID]) AS [curncyid],
  [CURRNIDX] AS [currnidx],
  RTRIM([RATETPID]) AS [ratetpid],
  RTRIM([EXGTBLID]) AS [exgtblid],
  [XCHGRATE] AS [xchgrate],
  [DENXRATE] AS [denxrate],
  [EXCHDATE] AS [exchdate],
  [TIME1] AS [time1],
  [RTCLCMTD] AS [rtclcmtd],
  [MCTRXSTT] AS [mctrxstt],
  RTRIM([TRXSORCE]) AS [trxsorce],
  [SOPHDRE1] AS [sophdre1],
  [SOPHDRE2] AS [sophdre2],
  [SOPLNERR] AS [soplnerr],
  [SOPHDRFL] AS [sophdrfl],
  RTRIM([COMMNTID]) AS [commntid],
  RTRIM([REFRENCE]) AS [refrence],
  [POSTEDDT] AS [posteddt],
  RTRIM([PTDUSRID]) AS [ptdusrid],
  RTRIM([USER2ENT]) AS [user2ent],
  [CREATDDT] AS [creatddt],
  [MODIFDT] AS [modifdt],
  [Tax_Date] AS [tax_date],
  [APLYWITH] AS [aplywith],
  [WITHHAMT] AS [withhamt],
  [SHPPGDOC] AS [shppgdoc],
  [CORRCTN] AS [corrctn],
  [SIMPLIFD] AS [simplifd],
  RTRIM([DOCNCORR]) AS [docncorr],
  [SEQNCORR] AS [seqncorr],
  [SALEDATE] AS [saledate],
  [EXCEPTIONALDEMAND] AS [exceptionaldemand],
  [Flags] AS [flags],
  [SOPSTATUS] AS [sopstatus],
  [SHIPCOMPLETE] AS [shipcomplete],
  [DIRECTDEBIT] AS [directdebit],
  [WorkflowApprStatCreditLm] AS [workflowapprstatcreditlm],
  [WorkflowPriorityCreditLm] AS [workflowprioritycreditlm],
  [WorkflowApprStatusQuote] AS [workflowapprstatusquote],
  [WorkflowPriorityQuote] AS [workflowpriorityquote],
  [Workflow_Status] AS [workflow_status],
  [ContractExchangeRateStat] AS [contractexchangeratestat],
  [Print_Phone_NumberGB] AS [print_phone_numbergb],
  [DEX_ROW_TS] AS [dex_row_ts],
  [DEX_ROW_ID] AS [dex_row_id]
FROM CHG.dbo.SOP30200
WHERE [DEX_ROW_TS] > ''{sop30200_ts}''
')
