I have a column in my database of data type Geography which I want to convert to a varchar.
I am using the following query to make do this …
— 1: Issue with Microsoft.SqlServer.Types.dll.
ALTER TABLE RetailerStore ALTER COLUMN Location VARCHAR(50)
However, I get the error message
Msg 257, Level 16, State 3, Line 1
Implicit conversion from data type geography to varchar is not allowed. Use the CONVERT function to run this query.
Has anybody come across this and if so do they know a way to resolve it?
There is no implicit conversion. Is there data in the column? If so, set it all to NULL before attempting to change the column type. Alternatively, you can drop and recreate the column.
Note that there is an explicit conversion from geography to a text form – you can use the STAsText to convert the spatial type to a text representation.
Using ALTER TABLE to DROP and ADD: