With ActiveSheet.QueryTables.Add(Connection:=Array(Array( _
"ODBC;DSN=Firebird;Driver=Firebird/InterBase(r) driver;Dbname=server:C:\interbase.Ib;CHARSET" _
), Array("=NONE;;UID=admin" )), Destination:=Range("A1" ))
.CommandText = Array( _
"select sum((amccomprimento/1000000)*(amclargura/1000000)*m.medvalormm*c.cambitola/1000*amcpecas)" & Chr(13) & "" & Chr(10) & "from amarrado a, cabamarra c, medidas m, amacelulas ac, producaoindustrial pi, prodindamarrado pa, ind" _
, _
"ustrializacao i" & Chr(13) & "" & Chr(10) & "where pi.pridata between '05/01/2008' and '05/31/2008'" & Chr(13) & "" & Chr(10) & "and (pi.maqcodigo=44 or pi.maqcodigo=41)" & Chr(13) & "" & Chr(10) & "and pa.piaentsai='E'" & Chr(13) & "" & Chr(10) & "and piaindproduto = i.indcodigo" & Chr(13) & "" & Chr(10) & "and pi.pricodigo=pa.pricodigo" & Chr(13) & "" _
, _
"" & Chr(10) & "and pa.amacodigo=a.amacodigo" & Chr(13) & "" & Chr(10) & "and a.indcodigo=1" & Chr(13) & "" & Chr(10) & "and i.sticodigo=2" & Chr(13) & "" & Chr(10) & "and pi.ultatualizacao > '04/01/2008'" & Chr(13) & "" & Chr(10) & "and a.amacodigo=ac.amacodigo " & Chr(13) & "" & Chr(10) & "and a.camcodigo=c.camcodigo " & Chr(13) & "" & Chr(10) & "and c.medbit=m.medcodigo " & Chr(13) & "" & Chr(10) & "and a" _
, "mccomprimento>=2100000" & Chr(13) & "" & Chr(10) & "and camtipo not in ('M', '2', 'S', '3')" )
.Name = "interbase"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.PreserveColumnInfo = True
.Refresh BackgroundQuery:=False
End With |