I have an Oracle 10g function, named ‘F_SMART_DATE()’, that returns a scalar DATE. It accepts a single VARCHAR2 parameter that is either a date string (e.g. ‘2011-01-01’, ‘3/29/1966’) or a ‘smart’ date (e.g. ‘m-1’ (one month ago), ‘yb-0’ (beginning of the current year)).
When I execute the function in SQL Developer, it works as expected:
--return 28-JUL-11
SELECT F_SMART_DATE('M-1') SMART_DATE FROM DUAL;
If I create a Crystal Report with a Command object using the same syntax, it works as expected.
If I create a String parameter in the Command object (named ‘AS_OF’) and attempt to pass it to the function, trouble starts.
Command object’s text:
--reference Oracle function
SELECT F_SMART_DATE({?AS_OF}) SMART_DATE FROM DUAL;
If I pass, M-1 (WITHOUT the single quotation marks), I get an error that reads: ‘Failed to retrieve data from the database. Details: ORA-00904: “M”: invalid identifier [Database Vendor Code: 904]’.
If I pass, ‘M-1’ (WITH the single quotation marks), the call works as expected.
Unfortunately, these syntactical variants don’t work either:
SELECT F_SMART_DATE(''' || {?AS_OF} || ''') SMART_DATE FROM DUAL;
SELECT F_SMART_DATE(''({?AS_OF})'') SMART_DATE FROM DUAL;
Ideally, I would be able to remove the quotation marks from the parameter dialog.
Does this work:
It’s been a while since I’ve used Crystal Reports, but as I recall the parameters work more like macros than bind variables.