2010-09-01 5 views
1

J'ai créé l'utilisateur stocké suivant l'exécution de l'opération.Comment puis-je appeler une procédure stockée ou une fonction stockée à partir de l'instruction de sélection sql

CREATE FUNCTION spherical_distance1(@a float, @b float, @c float , @Lat float, @Lng 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 

Le problème que je suis confronté est ici, quand je l'appelle la fonction emmagasinés spherical_distance1, il indique l'erreur comme « spherical_distance1 » est pas un nom de fonction intégrée reconnue.

SELECT *, spherical_distance1(12.9216667, 57.2958, 77.591667, Lat, Lng) AS distance 
FROM business3 
WHERE distance < 3 
AND StreetName LIKE '%jayanagar %' 
AND Keyword LIKE '%plumbing %' 
ORDER BY spherical_distance1(12.9216667, 57.2958, 77.591667, Lat, Lng); 

Répondre

1

Première erreur - c'est un USERFUNCTION pas STOREDPROCEUDRE

deuxième - pour appeler la fonction de l'utilisateur, vous devez utiliser

SELECT dbo.functionName() 

ainsi pour votre affaire

SELECT dbo.spherical_distance1(12.9216667, 57.2958, 77.591667, Lat, Lng) AS distance 
3

Dans le serveur SQL, vous devez préfixer les noms de fonction avec le schéma.

Très probablement, le vôtre sera dbo, alors essayez d'appeler

select *, 
    dbo.spherical_distance1(12.9216667 ,57.2958,77.591667,Lat ,Lng) as distance 
from 
    business3 
where 
    ((distance < 3) and (StreetName like '%jayanagar %') and (Keyword like '%plumbing %')) 
order by 
    distance -- don't need to repeat the function here 
0

vous devez inclure "dbo". avant le nom de la fonction dans votre requête ...

Questions connexes