Avatar of maximus35
maximus35

asked on 

Sql Query to get Closest Date to Today's Date

Hello People.

Situation:
2 access tables: Tasks, and  PCs
Tasks stores info about work orders, PCs stores info about user's computer or computers.

Tasks table has, for example:
TaskID, USERID, TaskDate, TaskType

PCs table has, for example:
PC-ID, PCName, PC-IP, PC-BIOS, PC-HDSize, PC-RAM, PC-SerialNum, PCAuditDate, and of course, USERID

Since many users may change computer due to replacement, malfunction, or even Departmental Changes(person only, not PC), PCs names are repeated or even have a different name in the table, hence, multiple records of the same PC with the same or different specs (PC-RAM, PC-HD, USERID), but the only diffrence that it presents is the PCAuditDate.

So here is what I'm trying to get; an SQL Query that checks the PCs table, and gets the PCName with the newest PCAuditDate or the one Closest to Today's Date.

This is what I have only:

"SELECT USER.EMAILADDR, USER.PHONE, USER.DEPT, " _
             & " PC.PCNAME, PC.TCPIP " _
             & " FROM USER, PCs WHERE [USER.USERID] = " & Me.USERID & _
             " AND PCs.USERID = " & Me.USERID

this works ok, but displays the incorrect PCName.


In advance, thank you for helping.

Microsoft AccessVisual Basic ClassicSQL

Avatar of undefined
Last Comment
maximus35

8/22/2022 - Mon