Visual Studio 2010 Report Builder查询报错相同键已添加如何解决
报错原因
你编写的SQL查询存在输出字段重名问题,报表工具在保存查询结构时会将每一个输出字段的名称作为唯一键存储,遇到重复的字段名就会触发该报错。
你提供的SQL中SELECT部分存在明显的重名别名:
w.Longitude as 'GPSLongitude', w.Latitude as 'GPSLongitude'
你把w.Longitude和w.Latitude两个不同字段的别名都设为了GPSLongitude,直接导致了键重复问题。
排查解决步骤
- 优先修正重名字段的别名:将纬度的别名修改为
GPSLatitude即可,对应修改后的SQL片段如下:
select o.companycode, o.name, w.StartTravelTime, w.DateAndTimeStart, w.DateAndTimeEnd, w.InspectionID , w.Longitude as 'GPSLongitude', w.Latitude as 'GPSLatitude', 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
- 检查其余输出字段是否存在重名:确认没有未设置别名的同名字段,比如你当前SQL中
o.Longitude、o.Latitude和前面的GPS开头的经纬度别名不存在冲突,不需要额外调整,如果后续新增字段要注意避免重名。 - 若修改字段后仍报错,检查参数配置:确认你用到的
@Param3、@Param4、@Param5三个参数没有重复声明的情况,部分报表工具会将参数名作为唯一键存储,重复的参数名也会触发同类报错。 - 重新执行查询验证问题是否解决。
内容的提问来源于stack exchange,提问作者T-Bow
相关产品推荐
相关产品推荐

