[英]A domain error occurred in SQL Server 2000 while updating the data
I have created a function like the one below 我创建了一个类似于下面的函数
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
I am using the above function to update a column in a table like below: 我正在使用上述功能来更新下表中的列:
Update test
set calc = dbo.fn_Calc(cast(Lat as float), cast(Long as float), dblLat, dblLong)
While running the above query I got the error. 在运行上面的查询时,我得到了错误。
"A domain error occured." “发生域错误。”
What can be causing this error? 是什么导致此错误?
Try this one - 试试这个-
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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.