#!ODBC;DSN=myodbc3;DRIVER={MySQL ODBC 3.51 Driver};DESC=MySQL ODBC 3.51 TEST DSN;DATABASE=Test;SERVER=Gilberto;UID=root;PORT=3306;OPTION=3;
#SELECT * FROM Assistencias ORDER by no_cli;

*Var,PAno,Ano referencia,4,

DROP TABLE IF EXISTS tmp;

CREATE TABLE tmp (
        n_doc       INT(6) UNSIGNED ZEROFILL DEFAULT '0000' NOT NULL ,
        mes         INT(4) UNSIGNED ZEROFILL DEFAULT '0000' NOT NULL,
        ValorFact   DOUBLE(16,2)             DEFAULT '0.00' NOT NULL,
        ValorGar    DOUBLE(16,2)             DEFAULT '0.00' NOT NULL,
        ValorMO     DOUBLE(16,2)             DEFAULT '0.00' NOT NULL,
        ValorPe     DOUBLE(16,2)             DEFAULT '0.00' NOT NULL
        );

INSERT INTO tmp 
      SELECT
      n_doc,
      MONTH(d_rec),
      0  , 
      0   , 
      tot_mo    , 
      tot_mat
      FROM 
      Assistencias
WHERE
     MONTH(d_rec)= PAno
#   GROUP BY    Mat,mes
;


SELECT
       Mes    ,
       ValorFact,
       ValorGar ,
       ValorMO  ,
       ValorPe  
FROM
      Tmp
#WHERE
GROUP BY
     mes
ORDER by
     mes
;

DROP TABLE IF EXISTS tmp;
