1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
| Sub CompleteTableauCommande()
'Déclaration des variables
Dim cnx As ADODB.Connection
Dim rst As ADODB.Recordset
'Instanciation des variables
Set cnx = New ADODB.Connection
Set rst = New ADODB.Recordset
Dim sql1 As String
Dim debutperiode As Date
Dim ddeb As String
Dim dfin As String
Dim i As Integer
Dim j As Integer
Dim result_sql
cnx.ConnectionString = "DSN=Stats;UID=***;PWD=***;"
cnx.Open
i = 1
'Changer la date de début d'année
For debutperiode = DateSerial(2008, 12, 29) To DateSerial(2009, 1, 4) Step 7
ddeb = Format(debutperiode, "dd/mm/yyyy")
dfin = Format(debutperiode + 6, "dd/mm/yyyy")
'Nombre total d'envois périodique (courrier ):
sql1 = "select m.mp_l, count(*), sum(c.cde_tot_ttc)" + _
" from e_cde c, e_mode_paiement m" + _
" where c.cde_ty_se_c = 'WV2'" + _
" and c.cde_mp_c in ('KM','KI','KW','KT', 'KA','KC', 'CA')" + _
" and c.cde_mp_c = m.mp_c" + _
" and c.cde_d between" + _
" to_date('" + ddeb + " 00:00:00' , 'dd/mm/yyyy hh24:mi:ss')" + _
" and to_date('" + dfin + " 23:59:59', 'dd/mm/yyyy hh24:mi:ss') " + _
" group by m.mp_l" + _
" order by 1"
rst.Open sql1, cnx
Range("B6:C11").Select
'result_sql = rst.Fields(1).Value
result_sql = rst.GetString(2)
ActiveCell.FormulaR1C1 = result_sql
rst.Close
i = i + 10
Next
End Sub |
Partager