select top(1)
Tb_Customer.ID
from
Tb_Customer
inner join
Tb_Agency_Eshterak on Tb_Customer.ID = Tb_Agency_Eshterak.CustomerID
where
Tb_Agency_Eshterak.TypeE = 2
order by
((convert(decimal(10), Tb_Customer.Lat) - '36.828381258846065')
(convert(decimal(10), Tb_Customer.Lat) - '36.828381258846065')) +
((convert(decimal(10), Tb_Customer.Lng) - '54.454983147717144')
(convert(decimal(10), Tb_Customer.Lng) - '54.454983147717144')) ASC
此查询是否有任何问题? 我不能在Sql Server中执行 这是紧急感谢
答案 0 :(得分:0)
您缺少括号)
。您的ORDER BY
子句中缺少运算符。我放置了乘法运算符,以使查询编译。另外,不建议在ORDER BY
子句中使用大表达式。
我建议您有一个persisted computed column,并在您的ORDER BY
子句中使用该列。
select top(1) Tb_Customer.ID
from Tb_Customer
inner join Tb_Agency_Eshterak
on Tb_Customer.ID=Tb_Agency_Eshterak.CustomerID
where Tb_Agency_Eshterak.TypeE=2
ORDER BY
((CONVERT(decimal(10),Tb_Customer.Lat)-'36.828381258846065') * (CONVERT(decimal(10),Tb_Customer.Lat)-'36.828381258846065')) + ((CONVERT(decimal(10),Tb_Customer.Lng) - '54.454983147717144') * (CONVERT(decimal(10),Tb_Customer.Lng) - '54.4549831477171'))