到目前为止,我所做的识别不正确付款的操作是运行不正确的查询并检索从12/01/2019开始的所有记录,然后将这些记录保存在临时表中。
使用不正确的表进行查询:
SELECT DISTINCT
CAST(P.ExternalId AS CHAR(25)) AS 'transID'
, CASE RTP.Activity
WHEN 0 THEN 'Payment'
WHEN 1 THEN 'Void'
END AS 'transType'
, P.TransactionCreateDate AS 'createdDate'
, P.Amount AS 'paymentAmount' <<< Payment column was being retrieved from wrong table.
, P.EffectiveDate AS 'paymentDate'
, CAST(P.Id AS NVARCHAR(50)) AS 'payment_Id'
, P.TransactionBatchId AS 'batchId'
, T.TenderTypeId AS 'TenderType'
, CAST(TType.Name AS CHAR(10)) AS 'PaymentType'
FROM
Payments P
INNER JOIN dbo.Tenders T
ON T.TransactionId = P.TransactionId
INNER JOIN dbo.TenderTypes TType
ON TType.Id = T.TenderTypeId
WHERE
CAST(P.TransactionCreateDate AS DATE) >= '12/01/2019'
ORDER BY
createdDate DESC
然后,我对查询进行更正,以检索从2019年12月1日开始的所有交易,但这次获得分类付款,并将其放入第二个临时表中。差异是955条记录。
使用正确的表格查询以获取付款金额:
SELECT DISTINCT
CAST(P.ExternalId AS CHAR(25)) AS 'transID'
, CASE RTP.Activity
WHEN 0 THEN 'Payment'
WHEN 1 THEN 'Void'
END AS 'transType'
, P.TransactionCreateDate AS 'createdDate'
, T.Amount AS 'paymentAmount'
, P.EffectiveDate AS 'paymentDate'
, CAST(P.Id AS NVARCHAR(50)) AS 'payment_Id'
, P.TransactionBatchId AS 'batchId'
, T.TenderTypeId AS 'TenderType'
, CAST(TType.Name AS CHAR(10)) AS 'PaymentType'
FROM
Payments P
INNER JOIN dbo.Tenders T
ON T.TransactionId = P.TransactionId
INNER JOIN dbo.TenderTypes TType
ON TType.Id = T.TenderTypeId
WHERE
CAST(P.TransactionCreateDate AS DATE) >= '12/01/2019'
ORDER BY
createdDate DESC
我的问题是,现在如何比较每个表的内容,以提取需要更正的内容?我确信这并不困难,我不知所措,无法弄清楚,想知道是否有人可以伸出援手。
非常感谢
EXCEPT接线员会解决您的问题吗?
SELECT A.a, A.b, ...
FROM Table A
EXCEPT
SELECT B.a, B.b, ...
FROM Table B;
Doc在这里:https : //docs.microsoft.com/zh-cn/sql/t-sql/language-elements/set-operators-except-and-intersect-transact-sql?view= sql-server- ver15
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。