SQL Statement IF Undefined

I have opened a connection to an Access database and am running a query but the IF statement seems to be causing a problem and I can’t see what it is. If the statement is true then col3, if it is false then I want which every number is bigger from either col6 or col7.

qry2=(“select col1, col2, col3, if(col4 < 1 OR col5 IS NOT NULL, col3, GREATEST(MAX(col6), MAX(col7))) as testcoldata from mytable”)

I get the error “Undefined function ‘if’ in expression.” If anyone could point me in the right direction. Thanks!

It’s been a few years since I constructed any SQL statements, but if I remember correctly, the if should be uppercase.

That aside, this is a Python Forum, rather than a SQL Forum.

It’s used in a python script.

but it’s a SQL statement.

1 Like

Apparently access calls it iif not if.

1 Like