penfold1234
New member
- Local time
- Today, 10:33
- Joined
- Nov 19, 2010
- Messages
- 4
Hi, I wonder if you can help?
I have an update query which I would like to use in order to update a number of records in a table. I want to assign each applicable record a ranking based on the record start date; earliest dated record gets the lowest ranking, incrementing by one each time. . . . so a set of 5 records receive the rankings 1,2,3,4,5 based on their start date.
I have written a select query called ‘RecordCountUpdateQuery’ which provides me with the sub group of records which need to be ranked and sorts them by StartDate. I have written the following update query to provide the ranking itself:
I have an update query which I would like to use in order to update a number of records in a table. I want to assign each applicable record a ranking based on the record start date; earliest dated record gets the lowest ranking, incrementing by one each time. . . . so a set of 5 records receive the rankings 1,2,3,4,5 based on their start date.
I have written a select query called ‘RecordCountUpdateQuery’ which provides me with the sub group of records which need to be ranked and sorts them by StartDate. I have written the following update query to provide the ranking itself:
Code:
[/SIZE][/FONT]
[FONT=Arial][SIZE=3] [/SIZE][/FONT]
[FONT=Arial][SIZE=3]UPDATE RecordCountUpdateQuery SET RecordCountUpdateQuery.RecordCount = DCount("GroupID","RecordCountUpdateQuery","StartDate <= [StartDate]");[/SIZE][/FONT]
[FONT=Arial][SIZE=3] [/SIZE][/FONT]
[FONT=Arial][SIZE=3][Code][/SIZE][/FONT]
[FONT=Arial][SIZE=3] [/SIZE][/FONT]
[FONT=Arial][SIZE=3]The problem is that the query updates all 5 records with the DCOUNT value, so I am left with a group of records which all have the record count value of 5 rather than 1,2,3,4,5. I had thought that the update query would execute for each line / record in the RecordCountUpdateQuery and as they were in order of date, the last portion of the DCOUNT query would cause the number to reduce by one each time. However this doesn’t happen. The query doesn’t appear to be looping or taking account of the last part of the DCOUNT.[/SIZE][/FONT]
[FONT=Arial][SIZE=3] [/SIZE][/FONT]
[FONT=Arial][SIZE=3]Is there a way I can get this to work. I’m not too hot on SQL so would ideally like to keep this simple if possible. [/SIZE][/FONT]
[FONT=Arial][SIZE=3] [/SIZE][/FONT]
[FONT=Arial][SIZE=3]Any help would be greatly appreciated . . . . [/SIZE][/FONT]
[FONT=Arial][SIZE=3] [/SIZE][/FONT]
[FONT=Arial]Thanks[/FONT]