如何“即时”返回带有存储过程中生成的值的附加列?
我在 SQL 2005 中有一个存储过程,它使用半正矢公式计算距离。一切都工作得很好,但我想用我的结果集返回计算出的距离。我该如何添加该列/值对?
DECLARE @Longitude DECIMAL(18,8),
@Latitude DECIMAL(18,8),
@MinLongitude DECIMAL(18,8),
@MaxLongitude DECIMAL(18,8),
@MinLatitude DECIMAL(18,8),
@MaxLatitude DECIMAL(18,8),
@WithinMiles INT
Set @Latitude = -122.25336930
Set @Longitude = 37.50002600
Set @WithinMiles = 20
-- Calculate the Max Lat/Long
SELECT @MaxLongitude = dbo.LongitudePlusDistance(@Longitude, @Latitude, @WithinMiles),
@MaxLatitude = dbo.LatitudePlusDistance(@Latitude, @WithinMiles)
-- Calculate the min lat/long
SELECT @MinLatitude = 2 * @Latitude - @MaxLatitude,
@MinLongitude = 2 * @Longitude - @MaxLongitude
SELECT Top 10 *
FROM Location
WHERE LocationLongitude Between @MinLongitude And @MaxLongitude
And LocationLatitude Between @MinLatitude And @MaxLatitude
And dbo.CalculateDistance(@Longitude, @Latitude, LocationLongitude, LocationLatitude) <= @WithinMiles
ORDER BY dbo.CalculateDistance(@Longitude, @Latitude, LocationLongitude, LocationLatitude)
--Return the result of dbo.CalculateDistance
有什么指点吗?包括问这个问题的正确方式?
(哦,是的,这不是存储过程,因为我直接使用查询,这就是我粘贴在此处的内容。)
I have a stored procedure in SQL 2005 that calculates distance using the Haversine formula. Everything works quite nicely but I'd like to return the calculated distance with my result set. How do I go about adding that column/value pair?
DECLARE @Longitude DECIMAL(18,8),
@Latitude DECIMAL(18,8),
@MinLongitude DECIMAL(18,8),
@MaxLongitude DECIMAL(18,8),
@MinLatitude DECIMAL(18,8),
@MaxLatitude DECIMAL(18,8),
@WithinMiles INT
Set @Latitude = -122.25336930
Set @Longitude = 37.50002600
Set @WithinMiles = 20
-- Calculate the Max Lat/Long
SELECT @MaxLongitude = dbo.LongitudePlusDistance(@Longitude, @Latitude, @WithinMiles),
@MaxLatitude = dbo.LatitudePlusDistance(@Latitude, @WithinMiles)
-- Calculate the min lat/long
SELECT @MinLatitude = 2 * @Latitude - @MaxLatitude,
@MinLongitude = 2 * @Longitude - @MaxLongitude
SELECT Top 10 *
FROM Location
WHERE LocationLongitude Between @MinLongitude And @MaxLongitude
And LocationLatitude Between @MinLatitude And @MaxLatitude
And dbo.CalculateDistance(@Longitude, @Latitude, LocationLongitude, LocationLatitude) <= @WithinMiles
ORDER BY dbo.CalculateDistance(@Longitude, @Latitude, LocationLongitude, LocationLatitude)
--Return the result of dbo.CalculateDistance
Any pointers? Including the correct way to ask this question?
(Oh, and yes, this is not the stored procedure since I was playing with the query directly that's what I pasted in here.)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我想这就是你所要求的
I think this is what your are asking for