@identity to get last entered ID

banks

Well-known member
Joined
Sep 7, 2005
Messages
50
Programming Experience
Beginner
Can i do this sql statement?

VB.NET:
sql2 = "INSERT INTO tblmaterialSupplier (materialId, SupplierID) values (SELECT @@identity FROM tblmaterials, '" & intSuppId & "')"
I can't get this sql to work - i need to get the last enetered materialId from my materials table...

Alex
 
"sql2 = "INSERT INTO tblmaterialSupplier (materialId, SupplierID) values (SELECT @@identity FROM tblmaterials, '" & intSuppId & "')" "

Try this...

SQL2 = "INSERT INTO tblmaterialSupplier (materialId, SupplierID) VALUES
(SELECT @@identity, '" & intSuppId & "' FROM tblmaterials)"
 
Try this in your stored proc mate.
Create an integer output parameter called @Id and after your insert statement
SET @Id = SCOPE_IDENTITY()

Should do the trick.
 
Back
Top