0

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

1 Answer 1

1

The Geography and Geometry data-types were not in SQL Server 2005. They were not introduced until SQL Server 2008.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks - aw shucks. Is there a work around for 2005? Or am I better off doing this in code?
The only work-around is to upgrade. And trying to do everything you need in code is going to be challenging to say the least. It's a lot easier to upgrade.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.