Вы находитесь на странице: 1из 2

Sort date field in XML Publisher template

I have been facing a continuous problem in a XML Publisher report. It seemed pretty trivial but I could not get it right. The report output had a date field and it was formatted while getting the data from the database to DD-MON-YYYY. Hence when the data came into the template it was interpreted as CHAR and the sorting was out of order. Although the data was sorted according to date from the database the output still did not show correctly. The output below shows Invoice Date, 01-Oct-09 before 01-Sep-09

Unsorted report After a lot of trying I got the idea to internally convert the date into numbers. The conversion would be YYYYMMDD. Once the date is converted to this number value and sorted as number, the records would be sorted properly. Hence I worked on the template.

Report template In the field, G_Line, which is the loop initiator I added the following after <?foreach?G_LINE_CLUSTER>, <?sort:concat(20,substring(TRX_DATE,8,2),(string-length(substringbefore(XXXJANFEBMARAPRMAYJUNJULAUGSEPOCTNOVDEC, substring(TRX_DATE,4,3))) div 3) + 10,substring(TRX_DATE,1,2));ascending;datatype=number?> The code for G_LINE field looked like,

After the change the records were sorted according to Invoice date as required,

Report sorted by Invoice Date

Вам также может понравиться