I have this table
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]
I want to write a query such that it will display all the companies within the 100 degree latitude and longitude of the company which I will select from drop down list.
Try this
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)
where Latitude between @lat - 100 and @lat + 100
and Longitude between @long - 100 and @long + 100
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.