1

I am getting an error indicating the wrong number of arguments when I run the following query:

SELECT
population_postcodes.*, 
target_postcodes.*, 
SQR( EXP(population_postcodes.longitude- target_postcodes.longitude, 2) + EXP(population_postcodes.latitude-target_postcodes.latitude, 2) ) as distance
FROM population_postcodes INNER JOIN target_postcodes on Population_postcodes.Population_postcode = Target_postcodes.Target_postcode;

Could anyone please suggest how I can fix this?

I have also tried the following code:

SELECT Population_postcodes.*, Target_postcodes.* 

FROM population_postcodes
INNER JOIN target_postcodes
ON Population_postcodes.Population_postcode = Target_postcodes.Target_postcode
SQR( (population_postcodes.longitude- target_postcodes.longitude)^2 + (population_postcodes.latitude-target_postcodes.latitude)^2 ) as distance;

And this code:

     SELECT Population_postcodes.*, Target_postcodes.*, SQR( (population_postcodes.longitude- target_postcodes.longitude)^2 + (population_postcodes.latitude-target_postcodes.latitude)^2 ) as distance
FROM population_postcodes
INNER JOIN target_postcodes
ON Population_postcodes.Population_postcode = Target_postcodes.Target_postcode;
Max F
  • 81
  • 2
  • 8
  • One idea would be to use the correct tags :) http://stackoverflow.com/questions/20994005/calculating-distance-pythagoras-and-running-count-in-sql-query#comment31549134_20994005 – Fionnuala Jan 08 '14 at 13:20
  • Haha Remou I get it, trying to fix it now, will remember the advice ;) – Max F Jan 08 '14 at 13:21

2 Answers2

0

Exp needs one parameter, you give two.

Old: EXP(population_postcodes.longitude- target_postcodes.longitude, 2)

New: (population_postcodes.longitude- target_postcodes.longitude)*(population_postcodes.longitude- target_postcodes.longitude)

Alexander
  • 19,906
  • 19
  • 75
  • 162
0

Try replacing...

EXP(<expression>, 2)

...to...

<expression>^2

In Access, the EXP function returns e (the base of natural logarithms) raised to a power. To raise an expression to a power, use the ^ operator.

In your case, be careful to put brackets around the expression, for example...

(population_postcodes.longitude- target_postcodes.longitude)^2

...to force the power to be applied last. By default, the ^ operator is evaluated before the - operator.

Brian Camire
  • 4,685
  • 2
  • 26
  • 23
  • Dear brian thanks for the help, however its still not working. Here's my current query: SELECT Population_postcodes.*, Target_postcodes.* FROM population_postcodes INNER JOIN target_postcodes ON Population_postcodes.Population_postcode = Target_postcodes.Target_postcode SQR( (population_postcodes.longitude- target_postcodes.longitude)^2 + (population_postcodes.latitude-target_postcodes.latitude)^2 ) as distance; – Max F Jan 08 '14 at 13:51
  • Try moving the `distance` expression to the `SELECT` clause, as in something like: `SELECT Population_postcodes.*, Target_postcodes.*, SQR( (population_postcodes.longitude- target_postcodes.longitude)^2 + (population_postcodes.latitude-target_postcodes.latitude)^2 ) as distance FROM population_postcodes INNER JOIN target_postcodes ON Population_postcodes.Population_postcode = Target_postcodes.Target_postcode;` – Brian Camire Jan 08 '14 at 14:10
  • for some reason it still yields an empty table with column names created representing both tables names and all of their columns as well as a new distance column... – Max F Jan 08 '14 at 14:13
  • Then there must be no records in `Population_postcodes` that have a `Population_postcode` equal to the `Target_postcode` of any record in `Target_postcodes`. – Brian Camire Jan 08 '14 at 14:27