Я не могу запустить его (очевидно), но как насчет этого ?:
SELECT
dbo.Transactions.CustomerCode,
dbo.Customer_Master.CustomerName,
dbo.Transactions.TransDate,
dbo.Transactions.PubCode,
dbo.Transactions.TransType,
dbo.Transactions.Copies,
'0' AS ReceiptNo,
'2008-01-01' AS PaymentDate,
0 AS Amount,
dbo.Transactions.Period,
dbo.Transactions.Year,
dbo.Publication_Master.PubName,
dbo.Customer_Master.SalesCode,
dbo.StreetSaleRcpt.CustomerCode,
SUM(dbo.Transactions.TotalAmount) AS TotalAmount,
COUNT_BIG(*) AS COUNT
FROM dbo.Publication_Master
INNER JOIN dbo.Customer_Master ON dbo.Customer_Master.CustomerCode = dbo.Transactions.CustomerCode
INNER JOIN dbo.Transactions ON dbo.Publication_Master.PubCode = dbo.Transactions.PubCode
LEFT OUTER JOIN dbo.StreetSaleRcpt ON (
dbo.StreetSaleRcpt.PubCode = dbo.Transactions.PubCode
AND dbo.StreetSaleRcpt.TransactionDate = dbo.Transactions.TransDate
AND dbo.StreetSaleRcpt.PeriodMonth = dbo.Transactions.Period
AND dbo.StreetSaleRcpt.PeriodYear = dbo.Transactions.Year
AND dbo.StreetSaleRcpt.Updated = 1
AND dbo.StreetSaleRcpt.CustomerCode = dbo.Customer_Master.CustomerCode
)
WHERE dbo.StreetSaleRcpt.CustomerCode IS NULL
GROUP BY
dbo.Transactions.CustomerCode,
dbo.Customer_Master.CustomerName,
dbo.Transactions.TransDate,
dbo.Transactions.PubCode,
dbo.Publication_Master.PubName,
dbo.Customer_Master.SalesCode,
dbo.Transactions.[Update],
dbo.Transactions.TransType,
dbo.Transactions.Copies,
dbo.Transactions.Period,
dbo.Transactions.Year,
dbo.Transactions.TotalAmount,
dbo.StreetSaleRcpt.CustomerCode
Сделайте ваш коррелированный подзапрос левым соединением и проверьте его отсутствие («WHERE dbo.StreetSaleRcpt.CustomerCode IS NULL») вместо «NOT IN».
Удачи.