Avonelle's Tech Blog

Go Back

Mistakes happen when you don’t know what you are doing

Here’s an example of how I screwed something up because I didn’t really think through HOW something worked. I’ve got a table of street addresses that currently has two columns for latitude and longitude values stored as doubles. Since I’m working with SQL Server 2008,I decided I wanted to create a new column for storing the data as a Geography data type so that I could perform some spatial functions on it.

So first I had to write the query to update this new column. And this is where I made my mistake:

update tblAddress set CenterPoint = (geography::Parse('POINT(' + str(longitude) + ' ' + str(latitude) + ')')) where Not latitude is null

Do you see it? I thought that rather than using the CONVERT function, I would just use STR to turn the longitude and latitude values into strings. Unfortunately, using STR as I used it rounded my values to integers. Not that useful when we are talking about values that look like this: 44.9072249

The result was that all my addresses (which are pretty much in the Twin Cities) had the same value in the new Geography column. Oops.

Just thought I’d share for the next guy. (Yeah, probably a waste of time because none of YOU would ever do anything so lame.)

Posted by Avonelle on Monday, August 23, 2010.

Facebook Twitter