views:

28

answers:

2

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)";
+1  A: 

How about putting @ sign in front of these parameters?

ppshein
Thanks for the reply i tried by putting @ in front Lat and Lng but it indicates error sayingMsg 137, Level 15, State 2, Procedure spherical_distance, Line 6Must declare the scalar variable "@Lat".CREATE FUNCTION spherical_distance(@a float, @b float, @c float)RETURNS floatASBEGIN RETURN ( 6371 * ACOS( COS( (@a/@b) ) * COS( (@Lat/@b) ) * COS( ( @Lng/@b ) - (@c/@b) ) + SIN( @a/@b ) * SIN( @Lat/@b ) ) ) END
mahesh
you forgot to write like that ... '" + lat + "' ... '" + lng + "'...
ppshein
+1  A: 

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.

treaschf