How to combine Max query in Insert query - learning purpose (1 Viewer)

SachAccess

Active member
Local time
Tomorrow, 03:36
Joined
Nov 22, 2021
Messages
389
Hi Experts,

I am doing it for learning purpose. I am trying to combine Max query with Insert query.
However, am not able to do it, can anyone please help me with this.
Both queries are working good if applied differently.

INSERT INTO tbllog ( id, [query name], [running time] )
VALUES (Max(ID) +1 FROM tbllog)), 1, 1);

SELECT Max(ID) +1 AS MaxID
FROM tbllog;

INSERT INTO tbllog ( id, [query name], [running time] )
VALUES (1, 1, 1);
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 06:06
Joined
May 7, 2009
Messages
19,245
you edit your tbllog table and change ID to Autonumber field.
there is no need to add Max(), it will increase automatically.


if you don't want to,:

Insert Into tbllog (id, [query name], [running time]) select Top 1 Nz(Max(ID), 0)+1, '1', 1 from tblLog;
 

SachAccess

Active member
Local time
Tomorrow, 03:36
Joined
Nov 22, 2021
Messages
389
Hi @arnelgp thanks a lot for the help. Have a nice weekend. :)
 

Users who are viewing this thread

Top Bottom