keithwarren7
keithwarren7

Reputation: 14280

SQL Geography string parsing

Why does this work

select geography::STGeomFromText('POINT(-77.010996 38.890358)',4326)

but this doesn't

declare @Latitude decimal(9,6) = 38.890358  
declare @Longitude decimal(9,6) = -77.010996

select geography::STGeomFromText('''POINT(' + 
cast(@Longitude as nvarchar(15)) + ' ' + 
cast(@Latitude as nvarchar(15)) +')''',4326)

What am I missing, they seem to be effectively the same thing.

Upvotes: 0

Views: 4401

Answers (1)

Conrad Frix
Conrad Frix

Reputation: 52645

Get rid of the extra quotes at the begining and end

declare @Latitude decimal(9,6) = 38.890358  
declare @Longitude decimal(9,6) = -77.010996

select geography::STGeomFromText('POINT(' + 
cast(@Longitude as nvarchar(15)) + ' ' + 
cast(@Latitude as nvarchar(15)) +')',4326)

Upvotes: 4

Related Questions