Converting a Date Format to YYYYMM in Cognos Report Studio

Excited_to_learn picture Excited_to_learn · May 29, 2014 · Viewed 20k times · Source

I have a date column in a format 12 May, 2014 I want to convert that into yyyymm/ 201405 format. i tried multiple options like

extract(year, sys_date)*100 + extract(month, sys_date))*100
cast(extract( year, sys_date), varchar(4)) + cast(extract( month, sys_date), varchar(2))

This one works but returns me in YYY,YMM format.

CAST(to_char(sys_date, 'YYYYMM'), INT )

For the above two, it gives an error:

 An error occurred while performing operation 'sqlOpenResult' status='-28'

Can some one please guide. Thank you in advance.

Answer

Excited_to_learn picture Excited_to_learn · May 29, 2014

I got what I was looking for. This is what I did:

translate(CAST(to_char(sys_date, 'YYYYMM'), varchar(6) ), ',' , ' ')

I am sure there would be a better way to get the result but for now I would use this SQL as it gives me what I want :)