Subject This code [1] works in IBExpert ...
Author Joel do Prado Junior
but when I try to run a IB_Query I get the following error message:

ISC ERROR CODE: 335544343

ISC ERROR MESSAGE:
invalid request BLR at offset 195
undefined parameter number


[1] http://pastebin.com/cQBe3Z3Z


If lines 20, 33, 43 and 55 are removed from the SQL runs on IB_Query.

Any suggestions?