如何在sql server中使用虚拟列过滤查询?

时间:2016-03-09 08:34:27

标签: sql-server

我想根据select语句中的虚拟列在查询中设置where条件。

Range("E2").AutoFill Destination:=Range("E2:E440")

有可能吗?

1 个答案:

答案 0 :(得分:3)

您可以直接指定:

select *,dbo.DictanceKM(cast(u.latitude as float),
                        @lat,cast(u.longitude as float),@long) as distance 
from Table u
where dbo.DictanceKM(cast(u.latitude as float),
                     @lat,cast(u.longitude as float),@long)<10

或使用子查询:

SELECT *
FROM (select *,dbo.DictanceKM(cast(u.latitude as float),
                              @lat,cast(u.longitude as float),@long) as distance 
      from Table u) sub
WHERE distance < 10