Click here to Skip to main content
15,891,708 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
SQL
DECLARE @g geography
SET @g=
geography::Point([Lat], [Long], 4326) as SAME_GEOM
FROM FencePointsBAHA FB
WHERE (Lat <> 0) AND (Long <> 0) and FenceIDFK=16
Posted
Updated 31-Mar-16 18:36pm
v4
Comments
Tomas Takac 31-Mar-16 4:17am    
Shouldn't it be SELECT @g = ...

1 solution

As Tomas Takac has commented you can use the Select @g = syntax.
SQL
DECLARE @g geography;
select @g= geography::Point([Lat], [Long], 4326)
FROM FencePointsBAHA FB
WHERE (Lat <> 0) AND (Long <> 0) and FenceIDFK=16
;

Ensure the where condition returns only one record, other wise the last record will populate the @g.

But the set will also work with a select statement:
SQL
DECLARE @g geography;
SET @g= (select geography::Point([Lat], [Long], 4326) as SAME_GEOM
FROM FencePointsBAHA FB
WHERE (Lat <> 0) AND (Long <> 0) and FenceIDFK=16)
;

When using the set method, ensure only one record is returned.

I usually use the select way to populate the variable if it is getting populated via a table record.

Hope that helps out.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900