Insert ID double...

Jelmer

Regular
Joined
Jan 11, 2006
Messages
96
A little problem.

I insert a field right this:

Code:
insert into veld1(row1,row2) values(1,2);

row0 is the ID field.
I want that row3 is the same as the id.
So:

Code:
insert into veld1(row1,row2,row3) values(1,2,[id]);

But wat doe i need to put into the [id] place??? to get the ID?? (the id must be generated by the database jet!!
 
Last edited by a moderator:
Scope_identity?

I have a small suspicion this won't work, and a greater suspicion it isn't the best approach available, but...

Code:
INSERT INTO veld1(row1, row2) VALUES (1,2);
UPDATE veld1 SET row3 = SCOPE_IDENTITY() WHERE row0 = SCOPE_IDENTITY();

SCOPE_IDENTITY() returns the identity of the last inserted record in the current scope.

Good luck

:cool:
 
This works for a part:

Code:
update bedrijven set debiteurnr = '(select max(ID) from bedrijven)' where id = (select max(ID) from bedrijven)

Ok.. the items have a different name..
But the field debiteurnr is a tekst field.
And if i run this code, the field gets this value:

(select max(ID) from bedrijven)

Thats not right... without the ' , it would work but then the database gives an error.
 
This code works:

update bedrijven set debiteurnr = id where id = (select max(ID) from bedrijven)

After the insert code... (id is the ID field).
 
Back
Top