1

我使用这个功能来获取 30 英里内的事件,它几乎与书呆子晚餐一样。但是我怎样才能通过'最近'订购它们..?

ALTER FUNCTION [dbo].[NearestEvents] 
  ( 
  @lat real, 
  @long real 
  ) 
RETURNS  TABLE 
AS 
  RETURN 
  SELECT Events.ID 
  FROM   Events  
  WHERE  dbo.DistanceBetween(@lat, @long, Latitude, Longitude) <30 
4

1 回答 1

3

将其添加到您的 SELECT 列表中。

SELECT Events.ID,
  dbo.DistanceBetween(@lat, @long, Latitude, Longitude) as distance
  FROM   Events  
  WHERE  dbo.DistanceBetween(@lat, @long, Latitude, Longitude) <30 
  ORDER BY distance

--由于它仍然不适用于 OP,因此调试存储过程的好方法是劫持参数。用你的查询分析器试试这个,看看你得到:

DECLARE @lat = varchar(100);
DECLARE @long = vavhar(100);

SET @lat = 'XXXXX';
SET @long = 'XXXXX';

 SELECT Events.ID,
      dbo.DistanceBetween(@lat, @long, Latitude, Longitude) as distance
      FROM   Events  
      WHERE  dbo.DistanceBetween(@lat, @long, Latitude, Longitude) <30 
      ORDER BY distance;
于 2011-01-10T23:44:50.053 回答