所以我有一份我正在尝试为我的班级创建的报告。我正在使用AdventureWorks
数据库,所以它并不复杂。我在 SQL Server Management Studio 和 HeidiSQL 中输入了我的 SQL 脚本,并且都返回了我正在寻找的结果,所以我很确定我的语法是正确的。但是,当我将查询输入 SSDT 时,会出现错误。关于为什么会发生这种情况的任何想法。
我的查询是这样的:
SELECT DISTINCT
s.Name AS 'Store Name',
c.FirstName AS 'Store Contact First Name',
c.LastName AS 'Store Contact Last Name',
c.Phone AS 'Store Contact Phone',
sm.Name AS 'Shipping Company Name',
soh.OrderDate AS 'Purchase Order Date',
soh.PurchaseOrderNumber AS 'Purchase Order Number',
e.Title AS 'Employee Title',
c1.FirstName AS 'Sales Person First Name',
c1.LastName AS 'Sales Person Last Name',
a.AddressLine1 AS 'Bill To Address',
a.City AS 'Bill To City',
sp.Name AS 'Bill To State',
cr.Name AS 'Bill To Country',
a.PostalCode AS 'Bill To Postal Code',
a1.AddressLine1 AS 'Ship To Address',
a1.City AS 'Bill To City',
sp1.Name AS 'Ship To State',
cr1.Name AS 'Ship To Country',
a1.PostalCode AS 'Ship To Postal Code'
FROM
Sales.SalesOrderHeader AS soh
LEFT OUTER JOIN
Sales.Store AS s ON soh.CustomerID = s.CustomerID
LEFT OUTER JOIN
Person.Contact AS c ON soh.ContactID = c.ContactID
LEFT OUTER JOIN
Purchasing.ShipMethod AS sm ON soh.ShipMethodID =sm.ShipMethodID
LEFT OUTER JOIN
HumanResources.Employee AS e ON soh.SalesPersonID = e.EmployeeID
INNER JOIN
Person.Contact AS c1 ON e.ContactID = c1.ContactID
LEFT OUTER JOIN
Person.Address AS a ON soh.BillToAddressID = a.AddressID
INNER JOIN
Person.StateProvince AS sp ON a.StateProvinceID = sp.StateProvinceID
INNER JOIN
Person.CountryRegion AS cr ON sp.CountryRegionCode = cr.CountryRegionCode
LEFT OUTER JOIN
Person.Address AS a1 ON soh.ShipToAddressID = a1.AddressID
INNER JOIN
Person.StateProvince AS sp1 ON a1.StateProvinceID = sp1.StateProvinceID
INNER JOIN
Person.CountryRegion AS cr1 ON sp1.CountryRegionCode = cr1.CountryRegionCode
就像我说的那样,我在 HeidiSQL 和 Microsoft SQL Server Management Studio 中得到了我想要的结果,但是一旦我尝试将它作为数据集添加到 VisualBasic Datatools 中,就会弹出错误说要么
无法为查询创建字段列表。验证您是否可以连接到数据源(我可以)以及您的查询语法是否正确(据我所知)。已添加具有相同密钥的项目。要继续不更新字段,请单击确定
我得到的另一个错误是:
无法为查询创建字段列表。验证您是否可以连接到数据源以及您的查询语法是否正确
任何想法或建议将不胜感激。