SELECT dbo.SVC00200.SRVTYPE, SVCHist.SRVRECTYPE, SVCHist.CALLNBR, SVCHist.SOPTYPE, SVCHist.SOPNUMBE, SVCHist.Invoiced_Amount, SVCHist.Amount_To_Invoice, SVCHist.CREATDDT, SVCHist.CREATETIME,
dbo.SVC00200.CUSTNMBR, dbo.SVC00200.CUSTNAME, dbo.SVC00200.PORDNMBR, dbo.SVC00200.Customer_Reference, dbo.SVC00200.COMPDTE, dbo.SVC00200.COMPTME, SOP.DOCDATE AS FinalDocDate,
SOP.DocAmt AS FinalDocAmt
FROM (SELECT SRVRECTYPE, CALLNBR, SOPTYPE, SOPNUMBE, Invoiced_Amount, Amount_To_Invoice, CREATDDT, CREATETIME, DEX_ROW_ID
FROM dbo.SVC00220
UNION
SELECT SRVRECTYPE, CALLNBR, SOPTYPE, SOPNUMBE, Invoiced_Amount, Amount_To_Invoice, CREATDDT, CREATETIME, DEX_ROW_ID
FROM dbo.SVC30220) AS SVCHist INNER JOIN
dbo.SVC00200 ON SVCHist.CALLNBR = dbo.SVC00200.CALLNBR INNER JOIN
(SELECT SOPTYPE, DOCID, SOPNUMBE, DOCDATE, CASE WHEN soptype = 4 THEN docamnt * - 1 ELSE docamnt END AS DocAmt
FROM dbo.SOP10100
UNION
SELECT SOPTYPE, DOCID, SOPNUMBE, DOCDATE, CASE WHEN soptype = 4 THEN docamnt * - 1 ELSE docamnt END AS DocAmt
FROM dbo.SOP30200) AS SOP ON SVCHist.SOPNUMBE = SOP.SOPNUMBE
No comments:
Post a Comment