Sub COMPRESS_TEST()
Dim oConn As ADODB.Connection
Dim oRec As Object
Dim strDriver As String, _
strServeur As String, _
strDataBase As String
strDriver = "{SQL Server}"
strServeur = "TonNomDeServerSQL"
strDataBase = "TonNomDeDatabase"
Set oConn = New ADODB.Connection
oConn.Open "Driver=" & strDriver & ";" & _
"Server=" & strServeur & ";" & _
"Database=" & strDataBase
'
SQLStringA = "Select [Account Type], [Account No_], [Accounting Type Orig], [Accounting Code Orig], [Accounting Code], [Currency Code], SUM([Amount]) , SUM([Amount (LCY)]), COUNT([Amount (LCY)]) FROM [" & strDataBase & "].[dbo].[6000$Owner Distrib_ Ledger Entry]"
SQLStringB = " WHERE [Posting Date] BETWEEN '2008-01-01' AND '2009-12-31' GROUP BY [Account Type], [Account No_], [Accounting Type Orig], [Accounting Code Orig], [Accounting Code], [Currency Code] ORDER BY [Account Type], [Account No_], [Accounting Type Orig], [Accounting Code Orig], [Accounting Code], [Currency Code];"
strMyQuery = SQLStringA & SQLStringB
Set oRec = oConn.Execute(strMyQuery, adCmdText)
Range("A3").CopyFromRecordset oRec
oConn.Close
Set oConn = Nothing
End Sub