Hi all, I am trying to do something that sounds easy but in fact is turning out to be very difficult.
I am trying to return data in DB2 where a field MTTRDT is equal to the current date..I know in DB2 I can use WHERE DB2 = CURRENT DATE........However my problem is that my MTTRDT field is not in date format..It is numeric and is yyyymmdd....I have managed to use the SUBSTR command to convert this to a proper date ie yyyymmdd to yyyy-mm-dd.
But I still cannot get this to only return data where MTTRDT (which is now yyyy-mm-dd) = Current Date..
The code below is close, even setting NULL if MTTRDT has a 0 but it falls over saying not vaild data type. Is there any way to get this to work so that I can have a rolling Day query....Thx Ray..
My Curent code is
'SELECT CASE WHEN MTTRDT = 0 THEN null ELSE DATE((SUBSTR(CHAR(MTTRDT),1,4) ||''-''|| SUBSTR(CHAR(MTTRDT),5,2) ||''-''|| SUBSTR(CHAR(MTTRDT),7,2))) END MTTRDT FROM MVXADTA.ODLINE
WHERE DATE((SUBSTR(CHAR(MTTRDT),1,4) ||''-''|| SUBSTR(CHAR(MTTRDT),5,2) ||''-''|| SUBSTR(CHAR(MTTRDT),7,2))) >= (current date) ')
I am trying to return data in DB2 where a field MTTRDT is equal to the current date..I know in DB2 I can use WHERE DB2 = CURRENT DATE........However my problem is that my MTTRDT field is not in date format..It is numeric and is yyyymmdd....I have managed to use the SUBSTR command to convert this to a proper date ie yyyymmdd to yyyy-mm-dd.
But I still cannot get this to only return data where MTTRDT (which is now yyyy-mm-dd) = Current Date..
The code below is close, even setting NULL if MTTRDT has a 0 but it falls over saying not vaild data type. Is there any way to get this to work so that I can have a rolling Day query....Thx Ray..
My Curent code is
'SELECT CASE WHEN MTTRDT = 0 THEN null ELSE DATE((SUBSTR(CHAR(MTTRDT),1,4) ||''-''|| SUBSTR(CHAR(MTTRDT),5,2) ||''-''|| SUBSTR(CHAR(MTTRDT),7,2))) END MTTRDT FROM MVXADTA.ODLINE
WHERE DATE((SUBSTR(CHAR(MTTRDT),1,4) ||''-''|| SUBSTR(CHAR(MTTRDT),5,2) ||''-''|| SUBSTR(CHAR(MTTRDT),7,2))) >= (current date) ')