问题描述
在使用SQL Server做多表关联时,遇到以下错误,由于字段排序规则不同,导致无法关联
![image.png](https://imgconvert.csdnimg.cn/aHR0cHM6Ly9jZG4ubmxhcmsuY29tL3l1cXVlLzAvMjAyMC9wbmcvNjcxOTcwLzE1OTQ3MTI3NTAwMzgtOTQzZjdkMTMtMjNlZS00ZWJhLTgwMmYtMmI0NWVhMmQzZDE3LnBuZw?x-oss-process=image/format,png#align=left&display=inline&height=213&margin=[object Object]&name=image.png&originHeight=213&originWidth=791&size=27697&status=done&style=none&width=791)
解决方案
在Join条件后加上collate Chinese_PRC_90_CI_AI
进行转义。
SELECT T1.*,COALESCE(T2.CUSTOMER_COUNT,0) AS RTD_CUSTOMER_COUNT,COALESCE(T3.CUSTOMER_COUNT,0) AS FREEZER_CUSTOMER_COUNT
FROM T1
LEFT JOIN T2 ON T1.MONTH = T2.MONTH AND T1.CUSTOMER_ID = T2.CustomerID
LEFT JOIN T3 ON T1.MONTH = T3.MONTH collate Chinese_PRC_90_CI_AI AND T1.CUSTOMER_ID = T3.CustomerID collate Chinese_PRC_90_CI_AI