ALTER PROCEDURE [dbo].[uspGetBusesByDepature]
-- Add the parameters for the stored procedure here
@vRouteNumber varchar(4),
@dtDepartureTime datetime,
@dtArrivalTime datetime,
@InDate datetime
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
DECLARE @DeparturePoint geography,
@Latitude float,
@Longitude float,
@Radius float
-- Insert statements for procedure here
SET @Latitude = (SELECT fRouteWayPointLatitude
FROM dbo.RouteWayPoint
WHERE vRouteNumber = @vRouteNumber
AND iSequence = 1)
SET @Longitude = (SELECT fRouteWayPointLongitude
FROM dbo.RouteWayPoint
WHERE vRouteNumber = @vRouteNumber
AND iSequence = 1)
SET @Radius = (SELECT fRouteWayPointRadius
FROM dbo.RouteWayPoint
WHERE vRouteNumber = @vRouteNumber
AND iSequence = 1) * 1000
SET @DeparturePoint = geography::Point(@Latitude, @Longitude, 4326)
SET @dtDepartureTime = CONVERT(varchar, @InDate, 101) + ' ' + CONVERT(varchar(8), @dtDepartureTime, 108)
SELECT gps.iVehicleID, sDesc AS vVehicleDescription, sRegNo AS [vVehicleRegNo],
SUBSTRING(CONVERT(varchar(8), MIN(dtTime), 108), 1, 5)
+ ' | ' + SUBSTRING(sDesc, 1, 4) + ' - ' +
SUBSTRING(sRegNo, 1, CHARINDEX('-',sRegNo,1)-1)
AS vVehicleText, MIN(dtTime) AS dtTime--,
--dbo.fnBusIsAssigned(gps.iVehicleID, @dtDepartureTime, @dtArrivalTime, @InDate) AS isAssigned
FROM dbo.GPSDataDW gps INNER JOIN Vehicles v
ON gps.iVehicleID = v.iVehicleID
WHERE dtTime BETWEEN DATEADD(MI, -30, @dtDepartureTime) AND DATEADD(MI, 30, @dtDepartureTime)
AND @Radius > @DeparturePoint.STDistance(geography::Point(fLatitude, fLongitude, 4326))
GROUP BY gps.iVehicleID, sDesc, sRegNo
END
任何能帮助我解决此错误的人都会检查我似乎没有立即调用/返回多个表的所有内容。
提前致谢。
答案 0 :(得分:0)
美好的一天,
我发现了我的问题。问题是造成这个问题的地理数据类型。之后我评论了这一行: -
SET @DeparturePoint = geography :: Point(@Latitude,@ Longitude,4326);
一切顺利,我不知道为什么会这样。