日期:2014-05-18  浏览次数:20714 次

有关sql的问题
数据库表:
CREATE   TABLE   [dbo].[dresstable](
[id]   [int]   IDENTITY(1,1)   NOT   NULL,
[x_dress]   [float]   NULL,
[y_dress]   [float]   NULL,
  CONSTRAINT   [PK_dresstable]   PRIMARY   KEY   CLUSTERED  
(
[id]   ASC
)WITH   (IGNORE_DUP_KEY   =   OFF)   ON   [PRIMARY]
)   ON   [PRIMARY]

insert   into     dresstable   values   ( '152.23265 ', '-89.300025 ')
insert   into     dresstable   values   ( '658.52 ', '9.300025 ')
insert   into     dresstable   values   ( '156.54265 ', '-8.025 ')
insert   into     dresstable   values   ( '15.265 ', '89.025 ')


给出一个地点坐标A,比如(35.268,-23.24),想在表里找出离地点A最近的那条数据id

------解决方案--------------------
我顶!!
------解决方案--------------------
alter procedure GetShortest
(
@x decimal(10,6),
@y decimal(10,6)
)
as
select top 1 * from dresstable order by (x_dress-@x)*(x_dress-@x)+(y_dress-@y)*(y_dress-@y)


运行它时:
execute GetShortest 35.268,-23.24