problem with creating stored procedure and view in sql server
I have following stored procedure code when i execute it gives an error saying invalid column name Lat , Lng .These Lat and Lng variables are parameters called from c# code behind with sql query indicated at last in this particular paragraph.
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
create view [dbo].[business] as
SELECT Id,
Name1,
ZipCode,
StreetName,
StreetNumber,
State1,
Lat,
Lng,
Keyword
FROM Business_Details
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)";
How about putting @ sign in front of these parameters?
When you are creating the spherical_distance
function, it does not know anything about the Lat
and Lng
expressions. Should these be two additional parameters of the function, like @a
, @b
and @c
were? (The function does not know anything about the view.)
Later when you call the function, you pass the value from colum Lat
into @a
, and from Lng
into @c
, so in the function these two parameters will contain the values from these columns.
精彩评论