question

marka92 avatar image
marka92 asked

Create a Stored Procedure that returns a geography type

Hi everyone, I am trying to create a stored procedure that returns some data, along with the geography type (location) from my tables in SQL. I am passing in a LocationID where the location will be matched against another table, only returning addresses that are 5, 10, 15, or 20 miles away from the location passed in. I am almost there but I am getting errors on the syntax. Here is my query: CREATE PROCEDURE [dbo].[prcGetSpatialLocation] @userDistance int Declare @distance sys.geography, @LocationID int Set @distance = (SELECT P.SpatialLocation, FROM dbo.Programs as P WHERE LocationID = @LocationID) AS BEGIN -- SET NOCOUNT ON added to prevent extra result sets from -- interfering with SELECT statements. SET NOCOUNT ON; SELECT H.CenterName, H.TypeofCenter, H.Address, H.City, H.State, H.ZipCode, H.PhoneNumber, H.Website, H.PatientServices, H.SpatialLocation, H.LocationID FROM [dbo].[HealthCenterAddresses] as H WHERE ((H.SpatialLocation.STDistance(@distance)) <= @userDistance) END GO What am I doing wrong???
stored-proceduresgeography
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
KenJ avatar image
KenJ answered
try moving the AS BEGIN to the line right after @userDistance int
3 comments
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

JohnM avatar image JohnM commented ·
Make sure to mark @KenJ's answer as the one that solved your issue. This will help others in the future that might have a similar issue as well as let people know that your question was answered. =)
1 Like 1 ·
marka92 avatar image marka92 commented ·
Ken, That worked great! Thank you.
0 Likes 0 ·
KenJ avatar image KenJ commented ·
You're welcome. I'm glad it got you going again.
0 Likes 0 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.