Sorry guys for the delay but it has been a busy week.

basically, this is the query I'm using and attached is a file with the classes used:

Select distinct kc.id,MSDS_UI_Serenity_Report.KitContentMissingType16_FindSerialNo(i.id,kc.id,9237,'00007SV3') As SerialNo, CASE WHEN i.Code IS NOT NULL THEN i.Code ELSE ' ' END As Code, MSDS_UI_Serenity_Report.KitContentType3_GetGroupedName(i.Name,kc.GroupFlag,kc.SubGroupFlag) As InstName, kc.Quantity as Qty,MSDS_UI_Serenity_Report.KitContentMissingType12_GetContentRemarks(k.Loc,k.id,kc.id,'00007SV3') As ContentRemarks, kc.GroupCount As GroupCount, g.Name As grp, MSDS_UI_Serenity_Report.KitContentMissingType16_Getpck(i.id,'00007SV3',kc.Quantity,kc.id,kc.kitId) As pck, MSDS_UI_Serenity_Report.KitContentMissingType15_GetDecon(kc.id,5) As decon, MSDS_UI_Serenity_Report.KitContentMissingType16_GetComments(i.id,kc.id) As Comment, MSDS_UI_Serenity_Report.KitContentMissingType16_GetReason(i.id,kc.id) As Reason, MSDS_UI_Serenity_Report.KitContentMissingType16_GetRemarks(i.id) As Remark 
     From MSDS_Serenity.KitContent kc, MSDS_Serenity.Kit k, MSDS_Serenity.InstrumentGroup g, MSDS_Serenity.Instrument i, MSDS_Serenity.CustomInstrument ci 
     where i.active = 1 and (i.IsImplants is null or i.IsImplants!=1) and kc.instrument = i.id and i.groupid = g.id and k.id = kc.kitid and k.Loc = 5 and k.id = 9237 order by kc.Position,i.Name

   

usedclassesdef.zip  

although all the fields used are indexed but still this sample query takes around 1 min & 40 sec to generate 48 records and some other queries with more records could take around 10 mins.

I noticed, that most time is consumed and heavy processing is in class calls in the query :

Eg. MSDS_UI_Serenity_Report.KitContentMissingType16_FindSerialNo around 40 sec but I’ve created and built indexes for all used fields (through SMP)!?

Thanks

Thanks again Vitaliy but we still going on cycles 😊 as I already you examples and I send you the a screenshot with the result and still not working, maybe I'm missing what you trying to say but I already tried option 1 with Timeformat=1 for the avg and didn't work.

your solution 1 or 2 works fine if querying the required field but not with avg, so eg. select %external(CAST(+avg(166.38) as TIME)) didn't work for me, maybe as you mentioned it's treating as double with floating precision that why it's cutting off the seconds, you mentioned the example above and I'm not sure to which one are youi refering to with so many replies, so can you point me to which one exactly because select %external(CAST(+avg(166.38) as TIME)) wouldn't work?

Thanks

Thank you very much Julie, your sample is exactly what I was looking for the only thing I need to add is some headings and information that I need to display at the top or the spreadsheet so I guess for that I can use Attributes!? And I also notice that elements aren’t widely supported in other formats ( pdf) and html tags aren’t supported in xlsx.

Thanks