Hi All,
I use dynamic SQL for performing some search operation.
Example: User inputs a value for fieldname on screen. I pick that value and run SQL on a table to identify all records that has the field name as input by the user.
I use dynamic SQL for the same (I cannot use static sql as there are additional fields that are input only at later point in time).
SqlFLDStr string is built as "'Select distinct a,b,c from lib/file where fieldname = ?"
Declare cursor routine
C/exec sql
C+ Prepare FldSqlStm from :SqlFldStr
C/end-exec
C/exec sql
C+ Declare C1 cursor for FldSqlStm
C/end-exec
Open cursor routine
C/exec sql
C+ Open C1 using :Fld1 // This is where i face problem when LIKE keyword is used
C/end-exec
If user inputs a value of ABC on screen, then my logic is fine.
However, if user inputs a value of %ABC on screen, then i have to find all records that include SSSABC, DDDABC, etc.
But the problem is, FLD1 is defined as 10 characters in length. I am unable to trim this field when passing it through the "Open Cursor dynamically". The program considers it as '%ABC_____' (with spaces at end to fill 10 characters) instead of '%ABC'
Any ways to solve this?
I use dynamic SQL for performing some search operation.
Example: User inputs a value for fieldname on screen. I pick that value and run SQL on a table to identify all records that has the field name as input by the user.
I use dynamic SQL for the same (I cannot use static sql as there are additional fields that are input only at later point in time).
SqlFLDStr string is built as "'Select distinct a,b,c from lib/file where fieldname = ?"
Declare cursor routine
C/exec sql
C+ Prepare FldSqlStm from :SqlFldStr
C/end-exec
C/exec sql
C+ Declare C1 cursor for FldSqlStm
C/end-exec
Open cursor routine
C/exec sql
C+ Open C1 using :Fld1 // This is where i face problem when LIKE keyword is used
C/end-exec
If user inputs a value of ABC on screen, then my logic is fine.
However, if user inputs a value of %ABC on screen, then i have to find all records that include SSSABC, DDDABC, etc.
But the problem is, FLD1 is defined as 10 characters in length. I am unable to trim this field when passing it through the "Open Cursor dynamically". The program considers it as '%ABC_____' (with spaces at end to fill 10 characters) instead of '%ABC'
Any ways to solve this?
Comment