grantwilliams
Programmer
Hi!
Hopefully this is a new one here and might give someone a challenge!
The task I've been given is to get the details of a selection of clients for the previous 12 months. The selections are as follows:
- Major clients who have approached us 3 or more times a month for the full year (on average)
- A random 5% of the remainder of clients for the year.
So, firstly I have the retrieved the ClientID and number of times the client has approached us for the years using the following SQL Query named getCount:
Secondly, I can retrieve the major clients and their details:
Thirdly, I can retrieve the remainder:
NB The Right(Format(Now,"Short Date"),2) is in there as the table this will be stored in, will store multiple years data, so the combination of the year and the ClientID form the Primary Key.
Now is where I run into trouble....
I need to be able to insert the details of all of the major clients into a table named tClientSurvey... I imagine I can do this with a Recordset and use a For loop and the MoveFirst, MoveNext commands to insert each record into the table.
I also need to insert a random 5% of the rest of the clients into the table. For this I thought I could once again use a Recordset and determine which records to insert using a Rnd * Recordset.length... however I do not know how to move to the record specified by Rnd * Recordset.Length....
Alternatively, I thought if I were able to insert all of the query data into an array, then I could use Rnd * Array.Length to get the ClientID's and then use a query to pull the remainder of the data out which could then be inserted into table.
OR if someone has a better suggestion, PLEASE PLEASE PLEASE come forth and let me know!![[smile] [smile] [smile]](/data/assets/smilies/smile.gif)
Hopefully this is a new one here and might give someone a challenge!
The task I've been given is to get the details of a selection of clients for the previous 12 months. The selections are as follows:
- Major clients who have approached us 3 or more times a month for the full year (on average)
- A random 5% of the remainder of clients for the year.
So, firstly I have the retrieved the ClientID and number of times the client has approached us for the years using the following SQL Query named getCount:
Code:
SELECT DISTINCT tRegister.ClientID, Count(tRegister.ClientID) AS Total
FROM tRegister
WHERE tRegister.DateCompleted >= 15/05/2003
GROUP BY tRegister.ClientID;
Secondly, I can retrieve the major clients and their details:
Code:
SELECT getCount.ClientID, Right(Format(Now,"Short Date"),2) AS IDCODE, tClient.DivisionID, tClient.BranchID
FROM tClient INNER JOIN getCount ON tClient.ClientID = getCount.ClientID
WHERE getCount.Total >= 36;
Thirdly, I can retrieve the remainder:
Code:
SELECT getCount.ClientID, Right(Format(Now,"Short Date"),2) AS IDCODE, tClient.DivisionID, tClient.BranchID
FROM tClient INNER JOIN getCount ON tClient.ClientID = getCount.ClientID
WHERE getCount.Total < 36;
NB The Right(Format(Now,"Short Date"),2) is in there as the table this will be stored in, will store multiple years data, so the combination of the year and the ClientID form the Primary Key.
Now is where I run into trouble....
I need to be able to insert the details of all of the major clients into a table named tClientSurvey... I imagine I can do this with a Recordset and use a For loop and the MoveFirst, MoveNext commands to insert each record into the table.
I also need to insert a random 5% of the rest of the clients into the table. For this I thought I could once again use a Recordset and determine which records to insert using a Rnd * Recordset.length... however I do not know how to move to the record specified by Rnd * Recordset.Length....
Alternatively, I thought if I were able to insert all of the query data into an array, then I could use Rnd * Array.Length to get the ClientID's and then use a query to pull the remainder of the data out which could then be inserted into table.
OR if someone has a better suggestion, PLEASE PLEASE PLEASE come forth and let me know!
![[smile] [smile] [smile]](/data/assets/smilies/smile.gif)