2017-01-06 68 views
3

TSQL MSSQL 2008R2CONVERT_IMPLICIT插入地理數據類型到一個地理數據類型列時

爲什麼以下進行CONVERT_IMPLICIT即地理數據類型轉換成地理數據類型?

DECLARE @xPolygon NVARCHAR(MAX) = '53.835134 -2.474670, 53.812436 -0.288391, 52.417944 -0.090637, 52.270286 -3.018494, 53.835134 -2.474670' 

IF OBJECT_ID('#xSpatialTable') IS NOT NULL 
    DROP TABLE #xSpatialTable; 
CREATE TABLE #xSpatialTable (
    id   INT IDENTITY (1,1) CONSTRAINT PK_xSpatialTable PRIMARY KEY 
    ,GeogCol1 GEOGRAPHY 
    ,GeogCol2 AS GeogCol1.STAsText() 
); 

INSERT INTO #xSpatialTable (GeogCol1) 
VALUES (GEOGRAPHY::STPolyFromText('POLYGON((' + @xPolygon + '))', 4326)); 

IF OBJECT_ID('#xSpatialTable') IS NOT NULL 
    DROP TABLE #xSpatialTable; 

從SentryOne SQL計劃資源管理器

CONVERT_IMPLICIT(地理,[地理] :: STPolyFromText((N'POLYGON(( '+ [@ xPolygon])+ N'))」, (4326)),0)

enter image description here

同樣這裏也適用

DECLARE @xLongitude FLOAT = 53.835134 
DECLARE @xLatitude FLOAT = -2.474670 

IF OBJECT_ID('#xSpatialTable') IS NOT NULL 
    DROP TABLE #xSpatialTable; 
CREATE TABLE #xSpatialTable (
    id   INT IDENTITY (1,1) CONSTRAINT PK_xSpatialTable PRIMARY KEY 
    ,GeogCol1 GEOGRAPHY 
    ,GeogCol2 AS GeogCol1.STAsText() 
); 

INSERT INTO #xSpatialTable (GeogCol1) 
VALUES (GEOGRAPHY::STGeomFromText('POINT(' + CAST(@xLongitude AS NVARCHAR(20)) + ' ' + CAST(@xLatitude AS NVARCHAR(20)) + ')', 4326)); 

IF OBJECT_ID('#xSpatialTable') IS NOT NULL 
    DROP TABLE #xSpatialTable; 

從SentryOne SQL計劃資源管理器

![enter image description here

有沒有辦法避免這些?

在此先感謝

+0

我沒有得到你的發佈代碼'CONVERT_IMPLICIT'。你可以添加一些你看到這個的截圖嗎? – iamdave

+0

截圖添加 –

+0

這就是我得到:http://i.imgur.com/DnxlGqa.png – iamdave

回答

0

與非臨時表dbo.xSpatialTable擺脫了Convert_Implicit取代了臨時表#xSpatialTable

相關問題