更新数据时SQL Server 2000中发生域错误

时间:2013-04-22 13:08:03

标签: sql-server sql-server-2000

我创建了一个类似下面的函数

ALTER  FUNCTION fn_Calc
(@Lat1  Float,
 @Lng1  Float,
 @Lat2  Float,
 @Lng2  Float)
RETURNS Float
AS
BEGIN

Declare @x      as Float
Declare @y      as Float
Declare @Distance   as Float

Select  @x = (SIN(RADIANS(@Lat1)) * SIN(RADIANS(@Lat2)) + COS(RADIANS(@Lat1)) * COS(RADIANS(@Lat2)) * COS(ABS((RADIANS(@Lng2)) - (RADIANS(@Lng1)))))
Select  @y = ATAN((SQRT(1-(POWER(@x,2))) / @x))

Select  @Distance = (1.852 * 60.0 * ((@y / PI()) * 180)) / 1.609344

RETURN  @Distance

END

我正在使用上面的函数来更新表格中的列,如下所示:

Update test 
set calc = dbo.fn_Calc(cast(Lat as float), cast(Long as float), dblLat, dblLong) 

运行上述查询时出错。

  

“发生域名错误。”

导致此错误的原因是什么?

1 个答案:

答案 0 :(得分:1)

试试这个 -

ALTER FUNCTION dbo.fn_Calc 
(
      @Lat1 FLOAT
    , @Lng1 FLOAT
    , @Lat2 FLOAT
    , @Lng2 FLOAT
)
RETURNS FLOAT
AS BEGIN

    DECLARE 
          @x FLOAT
        , @y FLOAT

    SELECT @x = 
                  SIN(RADIANS(@Lat1))
                * SIN(RADIANS(@Lat2)) + COS(RADIANS(@Lat1))
                * COS(RADIANS(@Lat2))
                * COS(ABS(RADIANS(@Lng2) - RADIANS(@Lng1)))

    SELECT @y = ATAN(SQRT(ABS(1 - POWER(@x, 2))) / @x)

    RETURN (111.12 * ((@y / PI()) * 180)) / 1.609344

END