Option Explicit
'On Error Resume Next
Dim objFSO, strServer, strServer2, objconnection, objconnection2
Dim objrecordset, objrecordset2, StartDate, i, sqlQuery
Dim date1
Const OpenFileForReading = 1:Const OpenFileForWriting = 2:Const OpenFileForAppending = 8
Const adopenstatic = 3:Const adlockoptimistic = 3:Const aduseclient = 3
Set objFSO = CreateObject("Scripting.FileSystemObject")
strServer = "LUBLAB"
strServer2 = "SFLAB"
StartDate = CDate(#2007-01-09#)
' sqlQuery = "Select count(*) as CallCount," & _
' "convert(char(10),FileDateTime ,110)as CallDate," & _
' "'LAB' as Site " & _
' "From dbo.master_index where FileDateTime Between " & _
' "convert(char(10),getdate()-405,110) AND convert(char(10),getdate(),110)" & _
' "Group by convert(char(10),FileDateTime ,110)"
For i = -403 To -1
date1 = DateAdd("d", i, StartDate)
sqlQuery = "Select count(*) as CallCount," & _
"'" & DateAdd("d", -1, date1) & "' as CallDate," & _
"'LAB' as Site " & _
"From dbo.master_index where FileDateTime >=" & _
"convert(char(10),'" & DateAdd("d", -1, Date1) & "',110) AND " & _
"FileDateTime <convert(char(10),'" & Date1 & "',110)"
Set objconnection = CreateObject("ADODB.Connection")
Set objconnection2 = CreateObject("ADODB.Connection")
Set objrecordset = CreateObject("ADODB.Recordset")
Set objrecordset2 = CreateObject("ADODB.Recordset")
objconnection.open "driver=SQL Server;server="&strserver&";uid=sa;pwd=passwd;database=RecDB;" 'open connection to source DB
objconnection2.open "driver=SQL Server;server="&strServer2&";uid=sa;pwd=passwd;database=testDB;" ' open connection to destination DB
objrecordset.Open sqlQuery, objconnection, adopenstatic, adlockoptimistic 'create a recordset with all the data you need
objrecordset2.Open "Select * From LoggerRecStats", objconnection2, adopenstatic, adlockoptimistic 'Create RecordSet for destination DB
'Do Until objrecordset.EOF 'loop through you data collected from the source
objrecordset2.AddNew 'add new record to destination DB; this would be like your insert query
'assign your values to the corresponding fields; just like the values section of your query
objrecordset2.Fields.Item("NumOfRecs").Value = objrecordset.Fields.Item("CallCount")
objrecordset2.Fields.Item("RecDate").Value = objrecordset.Fields.Item("CallDate")
objrecordset2.Fields.Item("Site").Value = objrecordset.Fields.Item("Site")
objrecordset2.Update 'update the recordset of the destination DB
' objrecordset.MoveNext
'Loop
Next
objrecordset.Close 'close the source recordset
objrecordset2.Close 'close the recordset of the destination
objConnection.Close 'close connection to source
objconnection2.Close 'close connection to destination