* phase 1 : grouping info SELECT ; DOW(Date) dateW ; , Shaa ; , PCode ; , Oper rowGroupNum ; && Oper must to be a INTEGER INTO CURSOR tempPhase1 READWRITE; FROM Yoman ; ORDER BY 1,2 && WHERE Date between m.lStartDate AND m.lStartDate+3 AND Bit NOT IN ("ì", "ð", "á" ) AND m.RofeCode IN ( M1, M2, M3, M4 ) * this numbers the rows of every group PRIVATE dateW,Shaa DO WHILE NOT EOF() SCATTER FIELDS dateW,Shaa MEMVAR REPLACE WHILE dateW=m.dateW AND CTime==m.Shaa rowGroupNum WITH _TALLY ENDDO RELEASE dateW,Shaa * final group transposition SELECT T.Shaa ; , MAX( IIF(dateW=1, Patient.Shem+Sug+left(NVL(SugTip.SugTipul," "),2) ,SPACE(28))) AS Sunday ; , MAX( IIF(dateW=2, Patient.Shem+Sug+left(NVL(SugTip.SugTipul," "),2) ,SPACE(28))) AS Monday; , MAX( IIF(dateW=3, Patient.Shem+Sug+left(NVL(SugTip.SugTipul," "),2) ,SPACE(28))) AS Tuesday ; , MAX( IIF(dateW=4, Patient.Shem+Sug+left(NVL(SugTip.SugTipul," "),2) ,SPACE(28))) AS Wednesday ; FROM tempPhase1 T; LEFT JOIN Patient ON T.PCode=Patient.Code ; LEFT JOIN Sugtip ON T.Tipul=SugTip.Code ; GROUP BY Shaa , rowGroupNum ; INTO TABLE mytesttable USE IN tempPhase1