我正在编写此查询,原始查询返回272行
SELECT
i.InvoiceId
,i.AccountCode AS ClientAccountCode FROM
vwInvoicesToSend i
JOIN
[SmartAdmin].dbo.Customers c ON i.AccountCode = c.AccountCode COLLATE DATABASE_DEFAULT
JOIN
InvoiceImages ii ON i.invoiceid = ii.invoiceid WHERE
i.BillRunId = 140
AND
c.BusinessGroup = 'xxxNZ'
我也有这个子查询返回5795行
WITH base AS (
SELECT Email, MAX(AccountCode) AS AccountCode FROM [SMPro5Profile].dbo.vwPFD_0000001848 WHERE AccountCode IS NOT NULL GROUP BY Email,AccountCode)
当我尝试在这两个查询之间执行内部联接时,我希望看到不超过272行。但我得到了1824行。
WITH base AS (SELECT Email, MAX(AccountCode) AS AccountCode FROM [SMPro5Profile].dbo.vwPFD_0000001848 WHERE AccountCode IS NOT NULL GROUP BY Email,AccountCode ) SELECT
i.InvoiceId
,i.AccountCode AS ClientAccountCode
--,base.AccountCode
--,base.[Email] FROM
vwInvoicesToSend i
JOIN
[SmartAdmin].dbo.Customers c ON i.AccountCode = c.AccountCode COLLATE DATABASE_DEFAULT
JOIN
InvoiceImages ii ON i.invoiceid = ii.invoiceid
INNER JOIN
base ON base.AccountCode = i.AccountCode COLLATE DATABASE_DEFAULT WHERE
i.BillRunId = 140
AND
c.BusinessGroup = 'xxxNZ'
我怀疑异常是由于COLLATE DATABASE_DEFAULT,因为两个引用列具有不同的归类定义。
无法解决" SQL_Latin1_General_CP1_CI_AS"之间的整理冲突和" Latin1_General_CI_AS"在等于操作。
有人知道如何解决这个问题吗?谢谢:))