Select field with double select possibilities

Hi all,
I got a select field and I need it changes behavior checking if another field is empty or not. Something like that (just to simplify)

IF {id_instrument} = “” THEN
SELECT serial_number FROM contract_instruments ORDER BY serial_number
ELSE
SELECT serial_number FROM contract_instruments WHERE id_instrument = {id_instrument} ORDER BY serial_number
END

I did tried using SELECT IF and CASE WHEN … but I’m not able to make it working.
I know that it has to be easy but I’m stuked… ;-((

i think you can try set your select SELECT serial_number FROM contract_instruments WHERE [g_where] ORDER BY serial_number

in onload you can evaluate.

IF {id_instrument} = “” THEN
[g_where] = “id_instrument > 0”;
ELSE
[g_where] = “id_instrument = {id_instrument}”;
END

Hey Alvagar… great… !!! You made my day ;-)) Thanks for hint

OnLoad and under Ajax Events connected to OnChange id_instrument …

IF ({id_instrument} == null)
{
[g_where] = " id_instrument > 0";
}
ELSE
{ [g_where] = " id_instrument = {id_instrument}";}