0

これは私のクエリがどのように見えるかです:

DECLARE @month date
DECLARE @CustomerId int
DECLARE @InterfacedSystemId int

SET @month = '2013-05-01'
SET @CustomerId = 24
SET @InterfacedSystemId = 1

SELECT * FROM
(
SELECT CONVERT(BIGINT,MisparHeshbonit) AS PreProcInvoiceNumber ,CONVERT(DATE,TaarichErech,103) AS PreProcDate , ROUND(sum(convert(float,SchumBruto)),2) AS PreProcSum  
FROM [VisaCalCredit] VCC
WHERE CONVERT(DATE,TaarichErech,103) BETWEEN @month AND DATEADD(DAY,-1,DATEADD(MONTH,1,@month))
      AND VCC.CustomerID = @CustomerID
GROUP BY MisparHeshbonit , CONVERT(DATE,TaarichErech,103)

) AS PreTable
ORDER BY PreProcInvoiceNumber, PreProcDate

SELECT * FROM
(
SELECT InvoiceNumber AS PostProcInvoiceNumber,ActualPaymentTime AS PostProcDate ,ROUND(sum(GrossAmount),2) AS PostProcSum 
FROM [CreditAndDebit] C INNER JOIN [Transaction] T ON C.TransactionID = T.ID 
WHERE ActualPaymentTime BETWEEN @month AND DATEADD(DAY,-1,DATEADD(MONTH,1,@month))
      AND T.CustomerID = @CustomerId
      AND T.InterfacedSystemID = 1
GROUP BY InvoiceNumber , ActualPaymentTime

) AS PostTable
ORDER BY PostProcInvoiceNumber ,PostProcDate

これらのテーブルで PreProcSum と PostProcSum の違いを見つける必要があります。また、内部テーブル自体の間で内部結合を作成できません (他の問題を引き起こす)。

このクエリで定義した 2 つのテーブル間でこの内部結合を行うにはどうすればよいですか?

4

1 に答える 1