I am trying to do the following query. Query1 will error out. Query2 works. Question: Does Query2 call the DoCalculate twice for every row processed? (One in the select and one in where clause.) If yes, how do I reduce the number of call to the function to 1?

Query1:

select DoCalculate(aLongitude,aLATITUDE,a.LONGITUDE,a.LATITUDE) mileage_calcualted
from TABLEx a
where mileage_calcualted is not NULL;


Query2:
select DoCalculate(aLongitude,aLATITUDE,a.LONGITUDE,a.LATITUDE) mileage_calcualted
from TABLEx a
where DoCalculate(aLongitude,aLATITUDE,a.LONGITUDE,a.LATITUDE) is not NULL;