-1

我在不同的地方遇到了这个错误,我不知道为什么,所以我想知道这里是否有人可能有任何线索。这是sql。

select Intranet.dbo.tblPeople.FirstName,
     Intranet.dbo.tblPeople.LastName,
     Intranet.dbo.tblPeople.CellPhone
     tblActivities.OnSiteSupervisorID,
     tblActivities.OffSiteSupervisorID,
     tblProjects.projectid,
     tblVehicleData.Description AS vehicle,
     tblVehicleData.VehicleID,
    tblVehicleData.ActivityID as ActivityID, 
     tblProjects.ProjectName,
     tblActivities.numPersons,
     tblActivities.Description,
     tblActivities.ChannelNumber,
     tblActivities.StartDate,
     tblActivities.EndDate,
     tblActivities.estimatedExitTime,
     tblLocations.locationname,
from Intranet.dbo.tblPeople,
     smartroadmangement.dbo.tblVehicleData,
     smartroadmangement.dbo.tblProjects,
     smartroadmangement.dbo.tblActivities 
left join smartroadmangement.dbo.tblLocations 
    on smartroadmangement.dbo.tblActivities.locationId = smartroadmangement.dbo.tblLocations.locationid
left join Intranet.dbo.tblPeople as people 
    on people.PersonID = smartroadmangement.dbo.tblActivities.OnSiteSupervisorID
left join tblActivities as Activities 
    on Activities.ActivityID = tblVehicleData.ActivityID
left join tblActivities as Activitiez 
    on Activitiez.ProjectID = tblProjects.ProjectID 
WHERE (smartroadmangement.dbo.tblActivities.StartDate Between '2012-07-15 14:17:09' and '2012-07-15 20:17:09') 
    AND (smartroadmangement.dbo.tblActivities.EndDate Between '2012-07-15 20:17:09'and '2012-07-15 23:17:09')
4

2 回答 2

5

我的第一个建议是在所有 JOIN 上使用正确的 JOIN 语法。您正在使用逗号和 JOIN 语法加入,这使得调试查询变得困难。

您的评论表明您在这里收到错误:

left join tblActivities as Activities 
    on Activities.ActivityID = tblVehicleData.ActivityID
left join tblActivities as Activitiez 
    on Activitiez.ProjectID = tblProjects.ProjectID

该表实际上smartroadmangement.dbo.tblActivities在您的查询中吗?

根据您在下面的评论,您可能想尝试:

left join smartroadmangement.dbo.tblActivities as Activities 
    on Activities.ActivityID = tblVehicleData.ActivityID
left join smartroadmangement.dbo.tblActivities as Activitiez 
    on Activitiez.ProjectID = tblProjects.ProjectID

这是一个使用正确的 JOIN 语法更新的查询:

select ppl.FirstName,
     ppl.LastName,
     ppl.CellPhone
     a1.OnSiteSupervisorID,
     a1.OffSiteSupervisorID,
     tblProjects.projectid,
     v.Description AS vehicle,
     v.VehicleID,
     v.ActivityID as ActivityID, 
     tblProjects.ProjectName,
     a1.numPersons,
     a1.Description,
     a1.ChannelNumber,
     a1.StartDate,
     a1.EndDate,
     a1.estimatedExitTime,
     l.locationname,
from Intranet.dbo.tblPeople ppl
left join smartroadmangement.dbo.tblActivities a1
    on ppl.PersonID = a1.OnSiteSupervisorID
left join smartroadmangement.dbo.tblLocations l
    on a1.locationId = l.locationid 
left join smartroadmangement.dbo.tblVehicleData v
    on a1.ActivityID = v.ActivityID
left join smartroadmangement.dbo.tblProjects pj 
    on a1.ProjectID = pj.ProjectID 
WHERE (a1.StartDate Between '2012-07-15 14:17:09' and '2012-07-15 20:17:09') 
    AND (a1.EndDate Between '2012-07-15 20:17:09'and '2012-07-15 23:17:09')
于 2012-07-30T20:51:19.967 回答
0

您使用的是四部分名称。您是否设置了名为 smartroadmangement 的链接服务器/别名?

于 2012-07-30T20:48:39.073 回答