对“无法绑定多部分标识符”感到困惑SQL 2008 中的错误
我创建了一个从多个表获取数据的视图,当我去编译它时,我不断收到“多部分标识符无法绑定”错误,这让我完全困惑于为什么。下面是我的 SQL 视图(错误消息来自粗体文本),请看一下并请帮助:
CREATE VIEW AMACO_VIEW_THIRD_PARTY_INSURANCE_INITIAL_LETTERS
AS
SELECT
CUSTOMERS.ID,
CUSTOMERS.FIRST_NAME,
CUSTOMERS.LAST_NAME,
CUSTOMER_ACCIDENT_DTLS.ACCIDENT_DATE,
CUSTOMER_ACCIDENT_DTLS.ACCIDENT_TIME,
HIRED_VEHICLES.HIRE_CHARGE_AMT,
CUSTOMER_STORAGE.START_DATE,
CUSTOMER_STORAGE.STORAGE_FEE_PER_DAY,
CUSTOMER_RECOVERY.RECOVERY_FEE,
THIRD_PARTIES.THIRD_PARTY_NAME,
THIRD_PARTY_VEHICLES.VEHICLE_REGISTRATION,
INSURANCE_COMPANIES.INSURANCE_COMPANY_NAME,
ADDRESSES.STREET_1,
ADDRESSES.STREET_2,
CITIES.CITY_NAME,
DISTRICTS.DISTRICT_NAME,
COUNTRIES.COUNTRY_NAME,
ADDRESSES.POSTAL_CODE
FROM CUSTOMERS, THIRD_PARTY_INITIAL_LETTER_PRINTED
LEFT JOIN CUSTOMER_ACCIDENT_HDRS
ON **CUSTOMERS.ID** = CUSTOMER_ACCIDENT_HDRS.CUSTOMER_ID
INNER JOIN CUSTOMER_ACCIDENT_DTLS
ON CUSTOMER_ACCIDENT_HDRS.ID = CUSTOMER_ACCIDENT_DTLS.CUSTOMER_ACCIDENT_HDR_ID
LEFT JOIN CUSTOMER_VEHICLES
ON **CUSTOMERS.CUSTOMER_VEHICLE_ID** = CUSTOMER_VEHICLES.ID
INNER JOIN THIRD_PARTIES
ON THIRD_PARTIES.CUSTOMER_ACCIDENT_ID = CUSTOMER_ACCIDENT_HDRS.ID
INNER JOIN THIRD_PARTY_VEHICLES
ON THIRD_PARTIES.THIRD_PARTY_VEHICLE_ID = THIRD_PARTY_VEHICLES.ID
INNER JOIN THIRD_PARTY_INSURANCE_POLICIES
ON THIRD_PARTIES.ID = THIRD_PARTY_INSURANCE_POLICIES.THIRD_PARTY_ID
INNER JOIN INSURANCE_POLICIES
ON THIRD_PARTY_INSURANCE_POLICIES.INSURANCE_POLICY_ID = INSURANCE_POLICIES.ID
INNER JOIN INSURANCE_COMPANIES
ON INSURANCE_POLICIES.INSURANCE_COMPANY_ID = INSURANCE_COMPANIES.ID
LEFT JOIN HIRED_VEHICLES
ON **CUSTOMERS.ID** = HIRED_VEHICLES.CUSTOMER_ID
INNER JOIN CUSTOMER_STORAGE
ON CUSTOMER_VEHICLES.ID = CUSTOMER_STORAGE.CUSTOMER_VEHICLE_ID
INNER JOIN CUSTOMER_RECOVERY
ON CUSTOMER_VEHICLES.ID = CUSTOMER_RECOVERY.CUSTOMER_VEHICLE_ID
INNER JOIN ADDRESSES
ON INSURANCE_COMPANIES.ADDRESS_ID = ADDRESSES.ID
INNER JOIN COUNTRIES
ON ADDRESSES.COUNTRY_ID = COUNTRIES.ID
INNER JOIN DISTRICTS
ON ADDRESSES.DISTRICT_ID = DISTRICTS.ID
INNER JOIN CITIES
ON ADDRESSES.CITY_ID = CITIES.ID
WHERE CUSTOMER_ACCIDENT_HDRS.ID NOT IN (SELECT THIRD_PARTY_INITIAL_LETTER_PRINTED.CUSTOMER_ACCIDENT_HDR_ID FROM THIRD_PARTY_INITIAL_LETTER_PRINTED)
GO
I created a view that gets data from several tables, whenI go to compile it I keep getting the "The multi-part identifier could not be bound" error which has me completely stumped as to why. Below is my SQL View (error messages coming from the bold text), take a look and please help:
CREATE VIEW AMACO_VIEW_THIRD_PARTY_INSURANCE_INITIAL_LETTERS
AS
SELECT
CUSTOMERS.ID,
CUSTOMERS.FIRST_NAME,
CUSTOMERS.LAST_NAME,
CUSTOMER_ACCIDENT_DTLS.ACCIDENT_DATE,
CUSTOMER_ACCIDENT_DTLS.ACCIDENT_TIME,
HIRED_VEHICLES.HIRE_CHARGE_AMT,
CUSTOMER_STORAGE.START_DATE,
CUSTOMER_STORAGE.STORAGE_FEE_PER_DAY,
CUSTOMER_RECOVERY.RECOVERY_FEE,
THIRD_PARTIES.THIRD_PARTY_NAME,
THIRD_PARTY_VEHICLES.VEHICLE_REGISTRATION,
INSURANCE_COMPANIES.INSURANCE_COMPANY_NAME,
ADDRESSES.STREET_1,
ADDRESSES.STREET_2,
CITIES.CITY_NAME,
DISTRICTS.DISTRICT_NAME,
COUNTRIES.COUNTRY_NAME,
ADDRESSES.POSTAL_CODE
FROM CUSTOMERS, THIRD_PARTY_INITIAL_LETTER_PRINTED
LEFT JOIN CUSTOMER_ACCIDENT_HDRS
ON **CUSTOMERS.ID** = CUSTOMER_ACCIDENT_HDRS.CUSTOMER_ID
INNER JOIN CUSTOMER_ACCIDENT_DTLS
ON CUSTOMER_ACCIDENT_HDRS.ID = CUSTOMER_ACCIDENT_DTLS.CUSTOMER_ACCIDENT_HDR_ID
LEFT JOIN CUSTOMER_VEHICLES
ON **CUSTOMERS.CUSTOMER_VEHICLE_ID** = CUSTOMER_VEHICLES.ID
INNER JOIN THIRD_PARTIES
ON THIRD_PARTIES.CUSTOMER_ACCIDENT_ID = CUSTOMER_ACCIDENT_HDRS.ID
INNER JOIN THIRD_PARTY_VEHICLES
ON THIRD_PARTIES.THIRD_PARTY_VEHICLE_ID = THIRD_PARTY_VEHICLES.ID
INNER JOIN THIRD_PARTY_INSURANCE_POLICIES
ON THIRD_PARTIES.ID = THIRD_PARTY_INSURANCE_POLICIES.THIRD_PARTY_ID
INNER JOIN INSURANCE_POLICIES
ON THIRD_PARTY_INSURANCE_POLICIES.INSURANCE_POLICY_ID = INSURANCE_POLICIES.ID
INNER JOIN INSURANCE_COMPANIES
ON INSURANCE_POLICIES.INSURANCE_COMPANY_ID = INSURANCE_COMPANIES.ID
LEFT JOIN HIRED_VEHICLES
ON **CUSTOMERS.ID** = HIRED_VEHICLES.CUSTOMER_ID
INNER JOIN CUSTOMER_STORAGE
ON CUSTOMER_VEHICLES.ID = CUSTOMER_STORAGE.CUSTOMER_VEHICLE_ID
INNER JOIN CUSTOMER_RECOVERY
ON CUSTOMER_VEHICLES.ID = CUSTOMER_RECOVERY.CUSTOMER_VEHICLE_ID
INNER JOIN ADDRESSES
ON INSURANCE_COMPANIES.ADDRESS_ID = ADDRESSES.ID
INNER JOIN COUNTRIES
ON ADDRESSES.COUNTRY_ID = COUNTRIES.ID
INNER JOIN DISTRICTS
ON ADDRESSES.DISTRICT_ID = DISTRICTS.ID
INNER JOIN CITIES
ON ADDRESSES.CITY_ID = CITIES.ID
WHERE CUSTOMER_ACCIDENT_HDRS.ID NOT IN (SELECT THIRD_PARTY_INITIAL_LETTER_PRINTED.CUSTOMER_ACCIDENT_HDR_ID FROM THIRD_PARTY_INITIAL_LETTER_PRINTED)
GO
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
部分
删除“查看查询的简化版本”
这将产生相同的错误。
如果您希望
CROSS JOIN
t1 和t2,则必须在使用其余连接之前执行此操作。像这样的东西
Remove the section
Have a look at this simplified version of your query
This will produce the same error.
If you wish to
CROSS JOIN
t1 and t2, you have to do that before you USE the rest of the joins.Something like
好吧,问题出在 THIRD_PARTY_INITIAL_LETTER_PRINTED 上,但问题是当我将它插入到外部 SELECT 语句中时,而不是子查询语句中。
Ok the problem WAS with THIRD_PARTY_INITIAL_LETTER_PRINTED, but it was when I was inserting it in the outer SELECT statement, not the sub-query statement.