I have created below stored procedures in SQL Server 2014.
Create procedure [dbo].[GetLocationsWithinDistance]
(
@latitude float,
@longitude float,
@distance float
)
AS
BEGIN
with LocationsWithDistance as
(
select
[Name] ,[Timings] ,Address, City ,
( 3959 * acos( cos( radians(@latitude) ) * cos( radians( [Lattitude] ) ) * cos( radians( [Longitude] )
- radians(@longitude) ) + sin( radians(@latitude) ) * sin( radians( [Lattitude] ) ) ) ) As Distance
--, more columns
FROM [QuickLoo].[dbo].[RestRoomSample]
)
select
[Name] ,[Timings] ,Address, City ,
Distance
from LocationsWithDistance
where Distance <= @distance
END
I am using this stored procedure in Entity Framework 6.0. I have called this in my C# code like below:
var resultFetch = context.GetLocationsWithinDistance(latitude, longitude, distance);
But this is returning no results and also there are errors or warnings. I am not able to figure out where is the issue. all other procedures without CTE expressions are returning result properly. It seems there are some issues with stored proc with CTE expression.
I am calling same in my SQL server which is working fine:
DECLARE @return_value int
EXEC @return_value = [dbo].[GetLocationsWithinDistance]
@latitude = 28.5744,
@longitude = 77.2387,
@distance = 2
SELECT 'Return Value' = @return_value
GO