问题
I recently started using SSRS reports and I am struggling to understand why I am getting the following error:
"The multi-part identifier 'ST.ProvinceID' could not be bound".
I understand what the error means, but I don't understand why it's not working in this instance. I have build quite a few SQL statements in my life, but for some reason, (of which I still need to figure out), SSRS SQL reports does not always work the same way a normal SQL query would.
Here is my execution code for the SSRS report:
SELECT DISTINCT [P].[Title], ST.Branch_CourtName, COUNT(DISTINCT UI.ID) AS NumUsers
FROM ITS___Structural_Location_Details ST, [User_Information_Maintenance] [UI]
JOIN [Province] [P]
ON [P].[ID] = ST.ProvinceID
WHERE ST.ProvinceID = UI.Province
GROUP BY ST.Branch_CourtName
I have double checked all the spelling for my table and column names. If you remove the JOIN it works, but I cannot see why it would not work in this instance.
This is a quick structure of all 3 tables.
Province: | ITS___Structural_Location_Details: | User_Information_Maintenance
ID | ID | ID
Title | ProvinceID | Province
Any help on this would be appreciated.
Thanks :)
回答1:
You should specify the tables separately in the join statements. If I understand your query correctly then you should be able to INNER JOIN your User_Information_Maintenance table and remove the WHERE clause..
SELECT DISTINCT [P].[Title]
, ST.Branch_CourtName
, COUNT(DISTINCT UI.ID) AS NumUsers
FROM ITS___Structural_Location_Details ST
INNER JOIN [Province] [P]
ON [P].[ID] = ST.ProvinceID
INNER JOIN [User_Information_Maintenance] [UI]
ON UI.Province = P.ProvinceId
GROUP BY ST.Branch_CourtName
回答2:
I also faces the same error, with one of my query, but i was using two tables in FROM clause. Then i removed one table from the query's FROM clause and used it as JOIN and error gone. hope this will help someone.
来源:https://stackoverflow.com/questions/20120081/why-am-i-getting-a-multi-part-identifier-could-not-be-bound-error