Sql-server – SQL Server latitude and longitude data type

google-maps, sql-server

I want to ask about what SQL Server data type to use for storing latitude and longitude.

Here's an example:

Latitude: -7.39755000Longitude: 107.80627000

If data type decimal, it won't save because SQL Server said:

cannot convert numeric data to numeric

as I remembered.

But if type data was float, SQL Server will convert 0 so the latitude will be -7.39755000. So I figure it out replace the last 0 with 1 - 9. is it the location will be not accurate?

Or maybe stick with decimal, but how to avoid the warning?

Best Solution

DECIMAL(9,6) is what I normally use for both. If you need more precision, then try DECIMAL(12,9).

You could also use the GEOGRAPHY data type, but it will take more space, and I would only recommend this if you need SQL Servers spatial features (indexing etc).

For the actual conversion, try this:

CAST(@YourLat AS DECIMAL(12,9))