![](/img/trans.png)
[英]LINQ to SQL: Invalid column name 'DepartureGate', even though the column exists
[英]SQL - Invalid column name, but it exists
尝试使用内部联接时出现错误。
列名“供应商 ID”无效。
该列存在于两个表中。
select p.ProductID, s.CompanyName, od.orderID
from OPENROWSET('SQLOLEDB', 'Server=DESKTOP-509LB9L\MSSQLSERVER01;Trusted_Connection=yes;',
'select ss.CompanyName from northwind.dbo.suppliers ss') s
inner join [DESKTOP-509LB9L\MSSQLSERVER01].northwind.dbo.products p
on s.SupplierID = p.SupplierID
inner join northwind.dbo.[Order Details] od
on od.ProductID = p.ProductID
inner join northwind.dbo.Orders o
on od.OrderID = o.OrderID
预期成绩:
ProductID CompanyName OrderID UnitPrice Quantity
1 Exotic Liquids 10249 42,40 35
2 Mayumi's 10250 35,40 10
3 Pavlova, Ltd. 10255 18,60 22
您需要 select SupplierID 在OPENROWSET
。 如果您在未选择列的情况下连接两个表,这就是您收到错误的原因。
只需添加ss.SupplierID
和ss.CompanyName
如下
select ss.SupplierID, ss.CompanyName from northwind.dbo.suppliers ss
您必须 select 子查询中的相应列供应商ID,
select p.ProductID, s.CompanyName, od.orderID
from OPENROWSET('SQLOLEDB', 'Server=DESKTOP-
509LB9L\MSSQLSERVER01;Trusted_Connection=yes;',
'select ss.CompanyName, SS.SupplierID from northwind.dbo.suppliers ss') s
inner join [DESKTOP-509LB9L\MSSQLSERVER01].northwind.dbo.products p
on s.SupplierID = p.SupplierID
inner join northwind.dbo.[Order Details] od
on od.ProductID = p.ProductID
inner join northwind.dbo.Orders o
on od.OrderID = o.OrderID
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.