I think I’m having a syntax problem, but I’m struggling to find an answer…
Could anyone explain why
SELECT TOP 3 * FROM Facilities
INNER JOIN FacilityStates
ON FacilityStates.Asset = Facilities.ID
WHERE Facilities.ID = 'MyFacility'
compiles and returns a suitable result, but what I think is the fully qualified version
SELECT TOP 3 * FROM [dbo].[Facilities]
INNER JOIN [dbo].[FacilityStates]
ON [dbo].[FacilityStates.Asset] = [dbo].[Facilities.ID]
WHERE [dbo].[Facilities.ID] = 'MyFacility'
throws “The multi-part identifier “x” could not be bound.” for the left and right parts of the ‘on’ clause and the ‘where’ clause?
Because you are combining your
Table.Columnin one set of square brackets:This should be:
Square brackets in SQL Server are used to explicitly denote an object name that could contain spaces or be a reserved word. So when you combined
FacilityStates.Assetwithin one set of brackets, you were telling SQL Server that there is an object with that name. Which there is not.