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 |
|
xrum
Yak Posting Veteran
87 Posts |
Posted - 2011-03-08 : 15:54:07
|
| I am trying to create a Trigger, that will update the History Table with Receipt Information.My Source Table has a SourceID and a ReceiptID.So when i Update Receipt table, i want to copy that record to the history table, but i first need to get the SourceID of the source that is being updated.this is what i have now:ALTER TRIGGER [dbo].[trg_ReceiptHistory] ON [dbo].[tblReceipt]for UPDATEAS begin tryINSERT INTO tblHistorySource(RecShipName, RecShipAddress, sourceID)select t1.shippingName, t1.shippingAddress, t2.sourceIDfrom [DELETED] t1, tblSource t2where t2.receiptID = t1.receiptIDend trybegin catchSELECTERROR_NUMBER() AS ErrorNumber,ERROR_SEVERITY() AS ErrorSeverity,ERROR_STATE() AS ErrorState,ERROR_PROCEDURE() AS ErrorProcedure,ERROR_LINE() AS ErrorLine,ERROR_MESSAGE() AS ErrorMessage;RAISERROR('Error in Source Hisotry Trigger' ,16,1)ROLLBACK TRANEND CATCHwhen i try to do a simple update to the tblReceipt, i get the following error:Msg 50000, Level 16, State 1, Procedure trg_ReceiptHistory, Line 24Error in Source Hisotry TriggerMsg 3609, Level 16, State 1, Line 1The transaction ended in the trigger. The batch has been aborted.Am I doing it wrong? please help :( |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
xrum
Yak Posting Veteran
87 Posts |
Posted - 2011-03-08 : 16:07:07
|
| thanks, i got it :) |
 |
|
|
|
|
|
|
|