Jossy
Jossy

Reputation: 999

Why am I getting "Invalid argument to function" error on my query?

I'm trying to run this query:

SELECT qry_performPrep2Elo_wta.PK_G, IIf([ID1_ocEdge]>0,[ID1_ocStake],0) AS ocStake, IIf([ID1_ocEdge]>0,[ID1_ocStake]*([ID1_ocmktPr]-1)) AS ocPL
FROM tbl_G_ov_wta INNER JOIN qry_performPrep2Elo_wta ON tbl_G_ov_wta.PK_G = qry_performPrep2Elo_wta.PK_G
WHERE (((tbl_G_ov_wta.ID1_G_Tot_Ov)>=(SELECT Min_games_wta FROM [tbl_ref_games] WHERE Surface = "All surfaces")));

But I get an "Invalid argument to function" error. If I remove the WHERE clause and run the following:

SELECT qry_performPrep2Elo_wta.PK_G, IIf([ID1_ocEdge]>0,[ID1_ocStake],0) AS ocStake, IIf([ID1_ocEdge]>0,[ID1_ocStake]*([ID1_ocmktPr]-1)) AS ocPL
FROM tbl_G_ov_wta INNER JOIN qry_performPrep2Elo_wta ON tbl_G_ov_wta.PK_G = qry_performPrep2Elo_wta.PK_G;

Everything works fine. I investigated the WHERE clause and couldn't see a reason for an issue. Indeed, when I remove the IIF statements but include the WHERE clause:

SELECT qry_performPrep2Elo_wta.PK_G
FROM tbl_G_ov_wta INNER JOIN qry_performPrep2Elo_wta ON tbl_G_ov_wta.PK_G = qry_performPrep2Elo_wta.PK_G
WHERE (((tbl_G_ov_wta.ID1_G_Tot_Ov)>=(SELECT Min_games_wta FROM [tbl_ref_games] WHERE Surface = "All surfaces")));

Everything runs fine.

The field PK_G is a primary key common across both the table and the query.

Any ideas?

Upvotes: 0

Views: 322

Answers (1)

Gustav
Gustav

Reputation: 55816

You missed the zero here:

IIf([ID1_ocEdge]>0,[ID1_ocStake]*([ID1_ocmktPr]-1),0)

Upvotes: 1

Related Questions