I am trying to create a stored procedure that returns all rows that are within a given lat/lng and search radius.
When I execute the create code (below) I get:
"Incorrect syntax near '<'"
It must be this line:
@p1.STDistance(geography::Point([LATITUDE], [LONGITUDE], 4326)) <= @searchRadius as [DistanceInKilometers]
Any ideas why?
Thanks
Here is the entire SPROC:
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: slinky66
-- Create date: 2013-06-26
-- Description: Returns all meeting locations within a given lat/lng and search radius
-- =============================================
CREATE PROCEDURE [dbo].[kiwone_GetNearMeetingLocationInKilometers_SP]
-- Add the parameters for the stored procedure here
@latitude decimal(18,14),
@longtitude decimal(18,14),
@searchRadius decimal (3,2),
@p1 geography
AS
BEGIN
SET NOCOUNT ON;
-- @p1 is the point you want to calculate the distance from which is passed as parameters
-- declare @p1 geography = geography::Point(@latitude,@longtitude, 4326);
select
c.LABEL_NAME,
k.*,
@p1.STDistance(geography::Point([LATITUDE], [LONGITUDE], 4326)) <= @searchRadius as [DistanceInKilometers]
from [USR_KIW_CUS_MEETING] as k
join CUSTOMER as c
on c.MASTER_CUSTOMER_ID = k.MASTER_CUSTOMER_ID
where c.USR_MEMBERSHIP_STATUS_CODE NOT IN('CR','CSD')
END
GO