How to use alias column name in where clause in SQL Server

后端 未结 5 1817
时光说笑
时光说笑 2020-11-27 06:49

When I tried to perform the below code in SQL Server 2005 I am getting the error

Invalid column name DistanceFromAddress

Code:<

5条回答
  •  [愿得一人]
    2020-11-27 07:03

    I think you can only use AS to display the final values. To do a comparision, the select should be returned from another select statement inside it.

    Like:

    SELECT a.disfromaddr FROM
     ( SELECT SQRT(POWER(cast(Program_Latitude as float) - cast('41.5126237' as float), 2) +   
     POWER(cast(Program_Longitude as float) - cast('-81.6516411' as float), 2)) * 62.1371192 
     AS DistanceFromAddress FROM tblProgram) 
    a WHERE a.disfromaddr < 2
    

    You can try this.

提交回复
热议问题