Bonjour, j'ai un problème de sql.
Voici le code :
J'utilise ce code pour déterminer les quartiles en statistiques pour chaque année de 2002 à aujourd'hui.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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 Function Quartil(strTable As String, strField As String, param As String, anne As String, rang As Integer) As Double Dim oDBS As DAO.Database Dim oRST As DAO.Recordset Dim blnEven As Boolean Dim vntMedian As Variant If rang = 1 Then rang = 25 If rang = 3 Then rang = 75 Set oDBS = CurrentDb() Set oRST = oDBS.OpenRecordset("SELECT * FROM " & strTable & " WHERE " & param & " = '" & CStr(anne) & "' ORDER BY " & strField) If oRST.EOF = False Then oRST.MoveLast blnEven = (oRST.RecordCount Mod 2 = 0) oRST.PercentPosition = rang vntMedian = oRST.Fields(strField) If blnEven Then oRST.MoveNext vntMedian = (vntMedian + oRST.Fields(strField)) / 2 End If End If oRST.Close Set oRST = Nothing Set oDBS = Nothing End Function
Problème : certaines années peuvent ne contenir aucune données pour certains produit. Donc la sélection peut être vide et donc j'ai une erreur. Comment compter le nombre de lignes de la sélection pour chaque année ?
Merci pour votre aide.
Partager