SELECT dato, tid, procent, formatnumber(IIf(procent=0,iif(procent=1,0,iif(mid(tid,4,2)=0,100,0)),(((mid(tid,4,2))*100))/60),2) & '%' AS minProcent1 FROM Tabel3 ORDER BY dato desc, tid desc;
Theoretically a motor could be started on an entirely different day, and could run days on end, so it would also be necessary to calcualte records for these hours two, ikke?
so it isnt something which can be done with a query, or at least I dont think so. Your going to have to use a temp table I think, with a function to loop through the records you have.
Det kan kun løses i VBA og en temp-tabel er påkrævet, da du ellers ikke kan vise posterne for hver time.
Så mit bud er, at man starter med at udfylde en tmp-tabel med alle timeslag og derefter finder ud af hvormange minutter i hver time, som er aktive. Endelig, i 2. eller 3. gennemløb, beregnes procenterne.
What you could have is a table which conatins a date and time for all hours of the day and also a column for containing your %.
Then the function loops through this table, maybe for a specific period so that the same calculation doesnt get done again.
For each record (date hour) the loops selects all of the records in your log table with the same date time. Then depending on what records are returned we can decide how to do the calculations for that day. There are a number of possibilities and you need to cover them all. For example, if there are NO records for that period, then it will be necessary to find out what the previous record was. Off then % = 0 On then % = 100
I'm sure you get the idea.
Does the log get deleted at some stage? I was thinking that it would be silly to loop through your An idea would to have a funtion which gets
loggen er en lille sort box som jeg resetter og sætter fast på en vilkårlig motor. via et interface kan jeg efter et par dage tilslutte den min PC og udtrække en csv fil med de nævnte kolloner. den logger tiden når den mærker ændringer i motorens viklinger. Derfor de mange skæve tidspunkter.
den laver en temptabel med poster for hvert minut - koden er noget hurtigere end hvis jeg skulle regne antal minutter for hver time.
Sub bygResTabel() DoCmd.RunSQL "delete * from tbltidspkt" Dim rs As ADODB.Recordset, rsRådata As ADODB.Recordset Dim i As Long Dim d_maks As Date, d_min As Date
Set rs = New ADODB.Recordset Set rsRådata = New ADODB.Recordset
rsRådata.Open "Select ([dato] + [tid]) as tidspunkt, aktiv from tblRådata order by [dato] + [tid] ", _ CurrentProject.Connection, adOpenDynamic, adLockOptimistic
rs.AddNew rs(0) = dtemp rs(1) = find(rsRådata, rs(0)) rs.Update dtemp = DateAdd("n", 1, dtemp) Loop rs.Close rsRådata.Close End Sub Function find(rs As ADODB.Recordset, tid As Date) As Double On Error Resume Next rs.find "tidspunkt > #" & Format(tid, "yyyy-mm-dd hh:nn:ss") & "#" If rs(1) = 0 Then find = 1 If rs(1) = 1 Then find = 0 End Function
Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.