【问题标题】:Why does my query does not work in Visual studio 2010 report builder为什么我的查询在 Visual Studio 2010 报表生成器中不起作用
【发布时间】:2023-03-03 14:22:01
【问题描述】:

我想在现有文件夹/项目下提交一份新报告。

新报告查询如下:

select o.companycode, o.name, w.StartTravelTime, w.DateAndTimeStart, w.DateAndTimeEnd, w.InspectionID , w.Longitude as 'GPSLongitude', w.Latitude as 'GPSLongitude', o.Longitude, o.Latitude, ACOS(SIN(PI()*w.Latitude/180.0)*SIN(PI()*o.Latitude/180.0)+COS(PI()*w.Latitude/180.0)*COS(PI()*o.Latitude/180.0)*COS(PI()*o.Longitude/180.0-PI()*w.Longitude/180.0))*6371 as 'Afwijking in km'
from Anticimex_WorkRecords w,
     CRM_Organisations o,
     Anticimex_Inspections i,
     Users u
where w.InspectionID = i.id
and i.BrancheOrganisationID = o.id
and u.id = w.userid
and w.DateAndTimeStart between @Param3 and @Param4
and u.username = @Param5

如果我想继续,我会收到以下错误:'保存查询设计方法时发生错误。已添加具有相同密钥的项目。'

【问题讨论】:

  • 您使用的是哪个 dbms? (上述查询是特定于产品的。)
  • 今日提示:始终使用现代、明确的JOIN 语法。更容易编写(没有错误),更容易阅读和维护,如果需要更容易转换为外连接!
  • sql server 管理工作室。如果我在那里运行查询,它就可以正常工作。
  • SSMS 是一种管理工具,而不是数据库。这意味着您正在使用 SQL Server。该错误抱怨报告,而不是查询
  • 我会删除数据集并重新开始。听起来您正在尝试向数据集的字段定义添加一个字段,但该字段已被定义。

标签: sql sql-server visual-studio-2010


【解决方案1】:
..., w.Longitude as 'GPSLongitude', w.Latitude as 'GPSLongitude',...

^ 很确定我找到了你的副本。如果您使用回车使查询更具可读性,这样的错字会更容易发现。

其他说明:

  • 请不要使用' 来分隔列或表的别名;这使它们看起来像字符串文字(并且语法在某些形式中已被弃用)。如果您需要避免糟糕的命名选择,请使用[square brackets]。 (更多关于别名here。)
  • 每个对象请always specify the schema
  • 请不要使用1980s-style joins

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-11-11
    • 2017-07-28
    • 2021-09-23
    • 1970-01-01
    • 2018-12-21
    相关资源
    最近更新 更多