If I run the following SQL using Oracle's SQL Developer.
select payee_id, to_char(check_date,'d') as DOW,
(cmcl_bank_cleared - check_date) as DateDiff from AP_Master
where (cmcl_bank_cleared is not null) AND ((cmcl_bank_cleared - check_date) >=1)
order by payee_address_zip, DOW, DateDiff
It works fine, however when I try to do it using Delphi
SQL.Add('select payee_id, to_char(check_date, ' + QuotedStr('d') + ') as DOW, ');
SQL.Add('(cmcl_bank_cleared - check_date) as DateDiff from AP_Master ');
SQL.Add('where (cmcl_bank_cleared is not null) AND ((cmcl_bank_cleared - check_date) >=:DaysParam))');
SQL.Add('order by payee_id, DOW, DateDiff;');
I get the "ORA-00933: SQL Command nor properly ended" error message
Look at the double bracket after DayParams. You don't have it in your SQL Developer SQL. To avoid you to use StackOverflow as an Oracle SQL spell checker, you could: