the right way for using "BETWEEN ascii(0) AND ascii(97)", would be to state
were column between ascii(0) and ascii(97)
why '0*', '1*', '2*' shows?
because the character '0' has a value of 41 in the ascii table, so it is between
ascii(0) and ascii (97). CHAR values are sorted by ascii value, position by position from left to right, so you'll have for instance:
the value considered is not the sum of the ascii values of the string.
Let's stick to what you really want to do in your clause. Please tell me with plain words what you want in your where clause. It looks strange for me that you can have non printable CHARACTERS in a where clause. There values are rarely 'human inputtable' at least.
your method of not filtering is a bit tricky and dangerous for a code maintenance point of view. According to which version you have, you can now prepare a statement within a stored procedure. You need IDS 11.50 or above.
In your case I would do something like
IF param1 IS NULL THEN
LET statement = "SELECT * FROM tablename";
LET statement = "SELECT * FROM tablename WHERE col1 BETWEEN " || param1 || "AND " || param2 ;
PREPARE prep_stmt FROm statement;
DECLARE mycursor FROM prep_stmt ;
OPEN CURSOR mycursor ;
fetch cursor..... ;