-1

我有这张桌子

CREATE TABLE [dbo].[EnquiryMaster](
    [EnquiryId] [int] IDENTITY(1,1) NOT NULL,
    [orgid] [int] NULL,
    [uid] [int] NULL,
    [Company] [varchar](160) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
    [HeadOfficeAddress] [varchar](460) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
    [ZipCode] [varchar](6) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
    [Latitude] [float] NOT NULL,
    [Longitude] [float] NOT NULL,   

    CONSTRAINT [PK_EnquiryMaster] PRIMARY KEY CLUSTERED 
    (
        [EnquiryId] ASC
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]

我想写一个查询,这样它将显示我将从下拉列表中选择的公司的 100 度纬度和经度内的所有公司。

4

2 回答 2

1

试试这个

select * 
from [dbo].[EnquiryMaster] 
where (Latitude <= @lat and Longitude <= @long 
      and Latitude + 100 >= @lat and  Longitude +100 >= @long)
OR (Latitude >= @lat and Longitude >= @long 
      and Latitude - 100 <= @lat and  Longitude -100 <= @long)
OR (Latitude >= @lat and Longitude <= @long 
      and Latitude - 100 <= @lat and  Longitude + 100 >= @long)
OR (Latitude <= @lat and Longitude >= @long 
      and Latitude + 100 >= @lat and  Longitude - 100 <= @long)
于 2013-02-25T06:52:44.703 回答
1
where Latitude  between @lat  - 100 and @lat  + 100
and   Longitude between @long - 100 and @long + 100
于 2013-02-25T08:21:05.987 回答