on 11-23-2017 9:25 PM
Hi everybody!
I have a scrip to execute a SQL instruction to get a max date, but my field StrDATE is like varchar(8). I need get the max value, but i dont know how to convert to date in sql instruction.
I try with something like this, but not works.
$G_UPDATE = sql('DB','select max(Strdate ) from tb01' );
Please somebody can help me.?
Thanks for your help.
$G_UPDATE = sql('DB','select max(Strdate ) from tb01' ); ---- >$G_UPDATE this variable should be varchar
This will give max data and will be store in the variable $G_UPDATE
Now create a new global variable $G_MAX_STR_DATE and in the same BODS script write
$G_MAX_STR_DATE=to_date($G_UPDATE,'YYYYMMDD')
or directly write
$G_UPDATE = sql('DB','select max(to_date(Strdate,'YYYYMMDD' ) from tb01' );
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Francisco,
The sql() function will return varchar as listed by document.
https://help.sap.com/viewer/8092b085a68941f6aaa6708685a62b0d/4.2.9/en-US/575fdf8f6d6d1014b3fc9283b0e...
You can use function to_date() to convert varchar to Date.
https://help.sap.com/viewer/8092b085a68941f6aaa6708685a62b0d/4.2.9/en-US/576031786d6d1014b3fc9283b0e...
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks Xia!
The problem is that apparently when I use the quotes in the sql to define format date 'yyyymmdd', for example:
$G_UPDATE = sql('DS','select max(to_date(DateStr,'yyyymmdd')) from tb01' );
When I check the syntax I get an error: "near <yyyymmdd> found <identifier> expecting < +,||..."
Regards.
User | Count |
---|---|
93 | |
10 | |
10 | |
9 | |
9 | |
7 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.