0
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

任何可以帮助我解决此错误的人我都会检查我似乎没有一次调用/返回多个表的所有内容。

提前致谢。

4

1 回答 1

0

再会,

我发现了我的问题。问题是导致此问题的地理数据类型。在我评论这条线之后: -

SET @DeparturePoint = geography::Point(@Latitude, @Longitude, 4326);

一切顺利,我不知道为什么会这样。

于 2013-10-08T06:26:20.710 回答