2016-07-13 34 views
0

我有以下查詢。我想將結果保存在我的Temp Table和isWithInCircle中的變量值也是如何呢?如何從我的查詢中保存臨時表中的數據

declare @source geography = geography::Point(30.221101852485987, 71.575927734375, 4326), @target geography = geography::Point(29.9358952133724, 71.817626953125, 4326); 

declare @radius_in_miles int = 100; 

declare @radius_in_meters float = @radius_in_miles * 1081.7316; 

select @target.STBuffer(@radius_in_meters).STContains(@source) AS [isWithinCircle], 
@target.STDistance(@source) AS [distance_in_meters], 
@target.STBuffer(@radius_in_meters).STDisjoint(@source) AS [isPastCircle]; 
+1

你爲什麼標記3個不同版本的SQL Server? – DavidG

+0

我認爲這有助於其他開發人員 –

+1

不,不重要的是您使用的是什麼版本。如果您希望它是版本不可知的,那麼不要標記特定的版本。如何v2014或v2016? – DavidG

回答

1

根據我有限的你正在嘗試做的,但這應該工作的認識......

IF OBJECT_ID('tempdb..#MyTempTable', 'U') IS NOT NULL DROP TABLE #MyTempTable; 

declare @source geography = geography::Point(30.221101852485987, 71.575927734375, 4326), @target geography = geography::Point(29.9358952133724, 71.817626953125, 4326); 

declare @radius_in_miles int = 100; 

declare @radius_in_meters float = @radius_in_miles * 1081.7316; 

declare @isWithinCircle int; 

select @target.STBuffer(@radius_in_meters).STContains(@source) AS [isWithinCircle], 
@target.STDistance(@source) AS [distance_in_meters], 
@target.STBuffer(@radius_in_meters).STDisjoint(@source) AS [isPastCircle] 
into #MyTempTable; 

select @isWithinCircle = isWithinCircle from #MyTempTable 

select @isWithinCircle 
+0

謝謝親愛的你:) –

相關問題