I have a file with having date field and I want to apply a substring on the date field. I can do this in SQL using the SUBSTR
function very easily. How can I do this using OPNQRYF
?
Sorry, you do not have permission to ask a question, You must login to ask a question.
Sorry, you do not have permission to ask a question.
I have a file with having date field and I want to apply a substring on the date field. I can do this in SQL using the SUBSTR
function very easily. How can I do this using OPNQRYF
?
To perform a
substring on a date field
, you will first have to cast the field to a string. This can be done using%char
.The below example will convert the date field to ISO DATEFMT first and then cast it to the character. After that, the substring (
%sst
) function is applied.%sst(%char(datefield "ISO") 1 4) *EQ '1980'
Now use it with OPNQRYF
OPNQRYF
FILE(libname/filename)
QRYSLT((%sst(%char(datefield "ISO") 1 4) *EQ '1980'))