T-SQL Tuesday #136 – My Favorite Data Type

T-SQL Tuesday is hosted this month by Brent Ozar (blog|twitter). The subject is what is your favorite or least favorite data type. As Brent describes it, “Your mission: write a blog post about your favorite data type“. Following is my opinion for T-SQL Tuesday #136 – My Favorite Data Type.

T-SQL Tuesday logo
T-SQL Tuesday logo

Around 2005/2007, I was charged with researching mapping visualizations and geo-spatial coding options for analytics. At the time, to employ any mapping visualizations was an expansive and complicated investment. It’s true that google maps and Bing were just starting to become more commoditized.

Enter SQL Server Spatial Geography Types. All of the sudden we have the ability to do relative distance, intersection calculations, as well as support for sophisticated visualizations via a SQL Server data type.

Now part of my SQL Server Purist background is making me want to go for something utilitarian like smallint (an eminently useful data type). But the fact that we got so much for nothing, and the fact that these data types behave like objects with methods, and the fact that mapping is such an important type of visualization for analytics, make SQL Server Spatial Geography Types my favorite.

In the intervening years, real-time geocoding and integrated visualizations like what we have in Power BI have made this data type not quite as essential as they once were. But I still have legacy clients that use geospatial queries to optimize sales territories. Also, the code to do this in something else (C#, etc) is way less elegent than the extended query forms. Less code is better code.

Here are some elementary queries that show how cools these capabilities still are. Run ’em in SSMS.
GeoSpatial Code Samples