I have a problem I cant seem to solve. Normally I'd just use a query to perform what I am trying to do, only this time I am using SQL CE.
I basically have 4 Tables.
TblCustomer
(PK1: CustomerId)
LnkCustomerLocation
(PK1: CustomerId,
PK2: LocationId)
TblLicence
(PK1: LicenceId,
FK1: CustomerId,
FK2: LocationId)
TblLicenceCheck
(PK1: LicenceCheckId,
FK1: LicenceId)
I need to pull back all Customers where a licence has not been checked since a date provided.
I need to filter the Customers and Licences within a certain location.
The steps I am trying to achieve:
1) Get the customers for the LocationId
2) Get the TOP 1 Licence for the LocationId and where related to the TraderIds found in Step 1 (this is done by DateTimeStamp)
3) Get the Top 1 LicenceCheck Record for each related LicenceId in Step 2 (done by DateTimeStamp).
So basically, I want the latest latest licence check for the latest licence for a particular location and trader.
It might appear wrong having both LicenceId link to both Customer and Licence, but trust me
there's a lot more going on which means I have to do that. This is just a very simplified version.