1
以下存儲過程會爲給定的緯度和經度回收最近的500個地址。許多應用程序使用它,它是有用的查詢之一。將複雜查詢(COS,SIN,RADIANS,ACOS)重寫爲實體至SQL
是否可以用Entity-to-SQL重寫?如果是這樣,請你指點我正確的方向(我對Entity-to-SQL並不陌生)?提前致謝。
DECLARE @CntXAxis FLOAT
DECLARE @CntYAxis FLOAT
DECLARE @CntZAxis FLOAT
SET @CntXAxis = COS(RADIANS(-118.4104684)) * COS(RADIANS(34.1030032))
SET @CntYAxis = COS(RADIANS(-118.4104684)) * SIN(RADIANS(34.1030032))
SET @CntZAxis = SIN(RADIANS(-118.4104684))
SELECT
500 *,
ProxDistance = 3961 * ACOS(dbo.XAxis(LAT, LONG)*@CntXAxis + dbo.YAxis(LAT, LONG)*@CntYAxis + dbo.ZAxis(LAT)*@CntZAxis)
FROM
tbl_ProviderLocation
WHERE
(3961 * ACOS(dbo.XAxis(LAT, LONG)*@CntXAxis + dbo.YAxis(LAT, LONG)*@CntYAxis + dbo.ZAxis(LAT)*@CntZAxis) <= 10)
ORDER BY
ProxDistance ASC