使用SQL的SSRS报告

时间:2014-11-28 04:04:50

标签: sql-server reporting-services ssms-2012 heidisql sql-server-2012-datatools

所以我有一份报告,我试图为我的班级创作。我正在使用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中,并且弹出错误说

  

无法为查询创建字段列表。验证您是否可以连接到数据源(我可以)并且您的查询语法是正确的(据我所知)。已添加具有相同键的项目。要继续更新字段,请单击“确定”

我得到的另一个错误是:

  

无法为查询创建字段列表。验证您是否可以连接到数据源并且查询语法是否正确

非常感谢任何想法或建议。

1 个答案:

答案 0 :(得分:2)

我最好的猜测是你有两个'Bill To City'专栏。我假设第二个你想成为'船到城'。从错误消息中听起来这可能导致问题。