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?
抛出“多部分标识符”x不能被绑定。“对于‘on’子句和‘where’子句的左、右部分?”
3 个解决方案
#1
3
Because you are combining your Table.Column
in one set of square brackets:
因为你在合并你的表。一组方括号内的一列:
....
ON [dbo].[FacilityStates.Asset] = [dbo].[Facilities.ID]
....
This should be:
这应该是:
....
ON [dbo].[FacilityStates].[Asset] = [dbo].[Facilities].[ID]
....
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.Asset
within one set of brackets, you were telling SQL Server that there is an object with that name. Which there is not.
SQL Server中的方括号用于显式地表示可以包含空格或保留单词的对象名称。所以当你把便利设施结合起来的时候。在一组括号中,您告诉SQL Server有一个具有该名称的对象。这没有。
#2
1
It's your placement of square brackets:
这是方括号的位置:
SELECT TOP 3 * FROM [dbo].[Facilities]
INNER JOIN [dbo].[FacilityStates]
ON [dbo].[FacilityStates].[Asset] = [dbo].[Facilities].[ID]
WHERE [dbo].[Facilities].[ID] = 'MyFacility'
#3
1
Try to figure out that everything inside square brackets is one name. You framed with sq. brackets table and field names together. The valid query is:
试着算出方括号内的所有东西都是一个名字。你用平方陷害。将表和字段名括在一起。有效的查询的方法是:
SELECT TOP 3 *
FROM [dbo].[Facilities]
INNER JOIN [dbo].[FacilityStates]
ON [dbo].[FacilityStates].[Asset] = [dbo].[Facilities].[ID]
WHERE [dbo].[Facilities].[ID] = 'MyFacility'
#1
3
Because you are combining your Table.Column
in one set of square brackets:
因为你在合并你的表。一组方括号内的一列:
....
ON [dbo].[FacilityStates.Asset] = [dbo].[Facilities.ID]
....
This should be:
这应该是:
....
ON [dbo].[FacilityStates].[Asset] = [dbo].[Facilities].[ID]
....
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.Asset
within one set of brackets, you were telling SQL Server that there is an object with that name. Which there is not.
SQL Server中的方括号用于显式地表示可以包含空格或保留单词的对象名称。所以当你把便利设施结合起来的时候。在一组括号中,您告诉SQL Server有一个具有该名称的对象。这没有。
#2
1
It's your placement of square brackets:
这是方括号的位置:
SELECT TOP 3 * FROM [dbo].[Facilities]
INNER JOIN [dbo].[FacilityStates]
ON [dbo].[FacilityStates].[Asset] = [dbo].[Facilities].[ID]
WHERE [dbo].[Facilities].[ID] = 'MyFacility'
#3
1
Try to figure out that everything inside square brackets is one name. You framed with sq. brackets table and field names together. The valid query is:
试着算出方括号内的所有东西都是一个名字。你用平方陷害。将表和字段名括在一起。有效的查询的方法是:
SELECT TOP 3 *
FROM [dbo].[Facilities]
INNER JOIN [dbo].[FacilityStates]
ON [dbo].[FacilityStates].[Asset] = [dbo].[Facilities].[ID]
WHERE [dbo].[Facilities].[ID] = 'MyFacility'