0

Ran into this issue with a Store Locator that I'm building. The Radians function returns a Zero (0) when executing SELECT RADIANS(47), but it returns 0.83... when executing SELECT RADIANS(47.0).

The ending result is causing the distance calculated by the sql statement to be Zero (0). I'm running on the following system:

  • OS Name Microsoft(R) Windows(R) Server 2003 Standard x64 Edition
  • Version 5.2.3790 Service Pack 2 Build 3790
  • System Model VMware Virtual Platform
  • System Type x64-based PC
  • SQL Server Microsoft SQL Server 2005

Here is the SQL statement that I'm using the radians function with.

SELECT TOP 15 i.* FROM ( 
    SELECT [id],[storeName],[storeNumber],[latitude],[longitude],

    ROUND((3959*acos(cos(radians([latitude])) * cos(radians( 47 )) 
    * cos(radians( -122.915 ) - radians([longitude])) + sin(radians([latitude])) 
    * sin(radians( 47 )))) , 2) AS distance 

    FROM [Public].[dbo].[stores] WHERE [latitude] <> 0 AND [longitude] <> 0 
) i WHERE distance < '50' ORDER BY i.distance 
4

1 回答 1

3

它按设计工作。根据文档,此函数返回与参数相同的类型。与简单运算符相同:select 5/2, 5.0/2 -- 返回 2 和 2.5

于 2012-12-14T18:36:31.417 回答