INSERT INTO X151106121334
(xgroup,DOCNO,REFNO,DATEDOC,XTRTYPE,XTRTYPE2,XID,XDESC,XUNIT1,LOCID,LOCDESC,XIDTYPE,XIDTDESC,REPBAL,COSTREPBAL,SHELF,NOMOVE,LINE,COST)
SELECT invmst.xSgroup,invcard.docno,invcard.orddoc,invcard.datedoc,invcard.trtype,invcard.trtype2,invcard.id,
invmst.xdesc,invmst.unit,invcard.locid,loca.locdesc,invmst.xidtype,idtype.idtdesc,invcard.repbal,invcard.costrepbal,invshelf.shelf,1,invcard.LINE,invcard.cost
FROM invcard LEFT JOIN invmst ON invcard.ID = invmst.ID
LEFT JOIN loca ON invcard.LOCID = loca.LOCID
LEFT JOIN idtype ON invmst.XIDTYPE = idtype.IDTID
LEFT JOIN invshelf ON invcard.id = invshelf.id and invcard.locid = invshelf.locid
WHERE (invcard.DATEDOC >= :mDATE1 AND invcard.DATEDOC <= :mDATE2) AND (invmst.xSgroup >= :mA1 AND invmst.xSgroup <= :mA2)
ORDER BY invcard.ID
