Update Flag on Max Date (1 Viewer)

Freshman

Registered User.
Local time
Today, 10:39
Joined
May 21, 2010
Messages
437
Hi all,

I've seen the answer to my question on a few places but just can't seem to implement it on mine. Maybe I'm missing something when changing their fields to mine, so I'll give my table and field names if someone can help please

Table: Career
Fields:
CareerID AutoNum and PK
ID Num (relationship to main table not relevant now)
SinceDate Date in question
MrkC Flag

I need to set the MrkC flag to -1 for the Max 'SinceDate' of each 'ID' row

I keep getting a not-updatable query error

Thanks a lot
 

jdraw

Super Moderator
Staff member
Local time
Today, 03:39
Joined
Jan 23, 2006
Messages
15,380
Please post the SQL of your not-updatable query.
It would be helpful to readers if you would provide a short description of what you're trying to do. And a few samples of your desired output would help with context.
 

Freshman

Registered User.
Local time
Today, 10:39
Joined
May 21, 2010
Messages
437
Hi there, sorry I thought I was clear enough.
I have a table with multiple 'SinceDate' for each 'ID' row
So I need to flag the Max 'SinceDate' for each 'ID'

I attached a database file where I do that using no less than 3 queries and one temp table - madness :)

PS: Hold down shift on open
 

Attachments

  • test.accdb
    376 KB · Views: 78

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 15:39
Joined
May 7, 2009
Messages
19,226
Code:
update Career inner join 
     (select [ID], max(SinceDate) as Expr1 group by [ID] from Career) AS T 
     on career.[ID] = T.[ID] and Career.[SinceDate]=T.[Expr1] 
set career.MrkC = -1;
 

Freshman

Registered User.
Local time
Today, 10:39
Joined
May 21, 2010
Messages
437
Code:
update Career inner join 
     (select [ID], max(SinceDate) as Expr1 group by [ID] from Career) AS T 
     on career.[ID] = T.[ID] and Career.[SinceDate]=T.[Expr1] 
set career.MrkC = -1;

Thanks for the speedy reply. Field is [ID] not [ID Num] sorry seems like I put the Data type to close to the field name.

Even when changing that I get the following error:

The SELECT steement included a reserved word or an argument name that is misspelled or misisng or the puntuation is incorrect

Here is the SQL I used:

update Career inner join
(select [ID], max(SinceDate) as Expr1 group by [ID] from Career) AS T
on Career.[ID] = T.[ID] and Career.[SinceDate]=T.[Expr1]
set Career.MrkC = -1
 

Gasman

Enthusiastic Amateur
Local time
Today, 08:39
Joined
Sep 21, 2011
Messages
14,216
Well it is hardly sensible using [ID] if the field is called [ID Num]?:confused:
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 15:39
Joined
May 7, 2009
Messages
19,226
create a query (query1)
Code:
SELECT career.id, Max(career.sincedate) AS Expr1
FROM career
GROUP BY career.id;
create the "final" update query adding query1 on the sql:
Code:
UPDATE Career SET Career.MrkC = -1
   WHERE career.careerid in  
   (select careerid from career t1 
   inner join query1 on t1.id = query1.id and t1.sincedate=query1.Expr1);
 

Freshman

Registered User.
Local time
Today, 10:39
Joined
May 21, 2010
Messages
437
create a query (query1)
Code:
SELECT career.id, Max(career.sincedate) AS Expr1
FROM career
GROUP BY career.id;
create the "final" update query adding query1 on the sql:
Code:
UPDATE Career SET Career.MrkC = -1
   WHERE career.careerid in  
   (select careerid from career t1 
   inner join query1 on t1.id = query1.id and t1.sincedate=query1.Expr1);

Thanks for the above - is there no way to combine it in a single update query?
Else it will have to do and in anyway much better than what I had :)
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 15:39
Joined
May 7, 2009
Messages
19,226
I already tried on my first post, but no..
 

Gasman

Enthusiastic Amateur
Local time
Today, 08:39
Joined
Sep 21, 2011
Messages
14,216
Well it is hardly sensible using [ID] if the field is called [ID Num]?:confused:

Well you changed your last post. but I owe you an apology. I misread the post as field being called [ID Num] as arnel had already used ID in his code?, so why mention it?:eek:

Getting late for me as well. :(
 

Users who are viewing this thread

Top Bottom