我正在尝试在sql server中创建以下存储过程Lat和Lng是从c#代码后面传递的参数。但是我无法创建这个存储过程 它表示错误,表示未定义的列名称Lat,Lng
CREATE FUNCTION spherical_distance(@a float, @b float, @c float)
RETURNS float
AS
BEGIN
RETURN ( 6371 * ACOS( COS( (@a/@b) ) * COS( (Lat/@b) ) * COS( ( Lng/@b ) - (@c/@b) ) + SIN( @a/@b ) * SIN( Lat/@b ) ) )
END
这是我在c#代码后面的查询。
sqlda.SelectCommand.CommandText = "select *, spherical_distance( Lat, 57.2958, Lng) as distance
from business
where (( distance < '" + radius + "' )
and (StreetName like '%" + streetname + "%')
and (Keyword like '%" + keyword1 + "%' ))
order by spherical_distance(Lat,57.2958,Lng)";
这是视图子句
create view [dbo].[business] as
SELECT Id,
Name1,
ZipCode,
StreetName,
StreetNumber,
State1,
Lat,
Lng,
Keyword
FROM Business_Details
答案 0 :(得分:1)
您将参数命名为@a和@c,而不是LON和LAT。
CREATE FUNCTION spherical_distance(@a float, @b float, @c float)
RETURNS float
AS
BEGIN
RETURN ( 6371 * ACOS( COS( (@a/@b) ) * COS( (Lat/@b) ) * COS( ( @c/@b ) - (@c/@b) ) + SIN( @a/@b ) * SIN( @a/@b ) ) )
END