05-30-2022 9:34 AM
Hi all,
i want to convert ERDAT to YYYY-MM-DD format directly in select statement in Database - MSSQL.
Date format YYYYMMDD to YYYY-MM-DD. is it possible?
Regards
05-30-2022 11:13 AM
Of course but the solution depends on the context of your development. Please clarify.
05-30-2022 11:54 AM
05-30-2022 3:06 PM
It works like follows but too late to do it in outside select.
CONCATENATE ls_out-erdat+0(4)
ls_out-erdat+4(2)
ls_out-erdat+6(2) INTO ls_out-erdat SEPARATED BY '-'.
05-30-2022 3:07 PM
05-30-2022 3:18 PM
Context is as follow. It is a normal select like ::
ERDAT ist 10 CHAR long.
REPORT ZCONTEXT.
Select single
CAST( erdat AS CHAR( 10 ) ) AS erdat,
from KNA1.
I just want to place "-" in between the year, month and date inside the select statement. so that it is JSON compatible date => YYYY-MM-DD
Thanks
05-30-2022 5:23 PM
You have the following SQL functions:
05-31-2022 7:01 PM
Sorry, this is really rather RTFM question that is impossible to answer without knowing technical details. You've mentioned it's MS SQL, so I'm guessing it's an older system and CDS views are not applicable in your case.
Look up documentation for SELECT statement for your ABAP version (use F1). All the functions will be described there, I doubt anyone can tell you something different here. There is also Native SQL option (which is covered in documentation) but I doubt it'll help or would be a good idea.
I'm curious about the context though and why is it important to do this in SELECT statement directly. I doubt it'll give you any "code pushdown" benefits.