PC SOFT

FOROS PROFESIONALES
WINDEVWEBDEV y WINDEV Mobile

Inicio → WINDEV 2024 → [OT] SQL question
[OT] SQL question
Iniciado por guest, 04,dic. 2015 11:35 - 2 respuestas
Publicado el 04,diciembre 2015 - 11:35
Hi,

I have a SQL-coding problem and would like to ask for tips.

I have 2 files TblBox and TblBoxMutatie like in the picture, with a 1:n relation, so one TblBox can have several TblBoxMutatie records:



I would like to create a list of unique TblBox-records with items TblBoxID, Boxnummer, TblKaastypeID and the items TblBoxMutatieID, TblLocatieID, Mutatietijd from file TblBoxMutatie, but for each TblBox-record only using 1 TblBoxMutatie-record. Depending on a parameter pardtDateTime (containing a datetime value) I want the TblBoxMutatie-record with the highest Mutatietijd value before this parameter value.

I've tried already. I can get the highest TblBoxMutatie.Mutatietijd value per TblBox, but I cannot get more items from that same TblBoxMutatie record.

Someone can help me with the best way to get this via SQL, if possible ?
Publicado el 04,diciembre 2015 - 12:41
try with something like this (not tested):

Select TblBoxID, Boxnummer, TblKaastypeID,TblLocatieID, Mutatietijd
from TblBox
left outer join TblBoxMutatie on TblBox.TblBoxID=TblBoxMutatie.TblBoxID
where
TblBoxMutatie.Mutatietijd= (select max(xx.Mutatietijd) from TblBoxMutatie xx
whre xx.TblBoxID=TblBoxMutatie.TblBoxID)
Publicado el 04,diciembre 2015 - 13:39
Hi Paulo,

this works indeed. Thank you for your effort.