ALTER PROCEDURE [dbo].[Trucks_byZipCodeAndRadius_Get]
@Zipcode varchar(10),
@Radius int
AS
BEGIN
DECLARE @latitude numeric(9,6), @longitude numeric(9,6)
SELECT @latitude = latitude,
@longitude = longitude
FROM dbo.Zipcode
WHERE zipcode = @Zipcode
SELECT TR.[TruckStartPointCity],
TR.[TruckEndPointCity],
TR.[TruckStartPointState],
TR.[TruckEndPointState],
TR.[TruckStartPointZip],
TR.[TruckEndPointZip],
TR.[TruckStartPointDate],
TR.[TruckEndPointDate],
T.*
FROM [dbo].[Truck] T INNER JOIN dbo.Truck_Route TR ON T.TruckRouteId = TR.TruckRouteId
WHERE T.TruckRouteId
IN (
SELECT TruckRouteId FROM dbo.Truck_Route
WHERE TruckStartPointZip IN
(
SELECT CAST( zipcode AS INT) FROM dbo.Zipcode
WHERE (SQRT(POWER(((latitude - @latitude) *69.1),2) +
POWER(((longitude - @longitude)*53),2)) <= @Radius)
)
)
END
|