Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
ConfusedAgain
Yak Posting Veteran
82 Posts |
Posted - 2012-01-31 : 12:15:22
|
I want to update the last inserted record in a table with the address details from another table.I have two tablesDeliveryAddressDeliveryAddress.AccIDDeliveryAddress.AddressAccountDetailsAccountDetails.AccIDAccountDetails.AddressWhen a record is inserted into the DeliveryAddress table the DeliveryAddress.AccID is populated but the Address is not. I need to pick this up from the AccountDetails table. Using After Insert trigger how can I do this?Hope that makes sense let me know if not.Thanks. |
|
ConfusedAgain
Yak Posting Veteran
82 Posts |
Posted - 2012-01-31 : 12:18:48
|
I should add there is a DeliveryAddress.ID that is an incremental Autonumber. as there may be muliple records of the DeliveryAddress.AccID and I only want to update the last record inserted. |
 |
|
DonAtWork
Master Smack Fu Yak Hacker
2167 Posts |
Posted - 2012-01-31 : 12:24:44
|
Can you show us the code that does the actual insert? You could probably do it from there and bypass the trigger entirelyhttp://weblogs.sqlteam.com/jeffs/archive/2008/05/13/question-needed-not-answer.aspxHow to ask: http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspxFor ultra basic questions, follow these links.http://www.sql-tutorial.net/ http://www.firstsql.com/tutor.htm http://www.w3schools.com/sql/default.asp |
 |
|
ConfusedAgain
Yak Posting Veteran
82 Posts |
Posted - 2012-01-31 : 12:27:39
|
The code that does the insert is in a vb.net form and that has no reference to the other table. It is an insert statement: mySqlCommand.CommandText = "INSERT INTO DeliveryAddress (AccID, AccountName, , UserName) " _ & "VALUES ( @pAccID, @pAccountName, @pUserName)" |
 |
|
ConfusedAgain
Yak Posting Veteran
82 Posts |
Posted - 2012-01-31 : 15:19:53
|
Can anyone help on this one I am a bit stuck?Thanks |
 |
|
ConfusedAgain
Yak Posting Veteran
82 Posts |
Posted - 2012-01-31 : 15:43:52
|
AFTER INSERTASUpdate DeliveryAddressSET DeliveryAddress.DelAdd1 = AccountDetails.Address1FROM AccountDetailsWHERE DeliveryAddress.AccID = AccountDetails.CompanyIDNo problem - I had a mental block. I have resolved this with the above. Thank you for looking. |
 |
|
|
|
|