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 |
|
hotshot_21
Yak Posting Veteran
97 Posts |
Posted - 2007-01-10 : 23:44:40
|
| How do i pass parameter to trigger.iam using trigger to delete from multiple tables here is the codeCreate trigger DeletePartyName on PartyMaster_Gen (@PartyName varchar(50))for deleteas DELETE FROM PartyMaster_Address WHERE PartyName=@PartyNameDELETE FROM PartyMaster_DEPB WHERE Party_Name=@PartyNameDELETE FROM PartyMaster_Gen WHERE Party_Name=@PartyNameI want to pass @partyname parameter to this query. how do i do it. |
|
|
jezemine
Master Smack Fu Yak Hacker
2886 Posts |
Posted - 2007-01-11 : 00:42:22
|
you can't do this. think about it: who would pass the param? www.elsasoft.org |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2007-01-11 : 01:49:44
|
| Rewrite TRIGGER as a STORED PROCEDURE...With your code above, you are triggering yourself! Trigger is on partymaster_gen, and the trigger deletes from the same table...Or make the TRIGGER auto sensitive (remove data for all three tables where partyname is involved)Create trigger DeletePartyName on PartyMaster_Gen for deleteas DELETE FROM PartyMaster_Address as p where exists (select null from deleted as d where d.partyname = p.partyname)DELETE FROM PartyMaster_DEPB as p where exists (select null from deleted as d where d.partyname = p.party_name)And yuo fire the trigger by executingdelete from partymaster_gen where party_name = 'Some party name here'Peter LarssonHelsingborg, Sweden |
 |
|
|
X002548
Not Just a Number
15586 Posts |
|
|
hfloresve
Starting Member
2 Posts |
Posted - 2012-09-14 : 14:45:00
|
| So late, but for new ppl who have this question, i describe my solution:I will describe sample with different tables...Table1Name: ComponentsComponent_iD (Pk)Component (name component)table 2Name: HistoryHistory_iD (Pk)Component_iDComponentModifiedByDate... etc1.- Create trigger on table 1 to write in my historytable after insert/update2.- Create a stored procedure to insert on table 1, and input parameter "@username"3.- On my stored procedure i get @@Identity from generated record (after insert, when update just take component_id)4.- Update ModifiedBy field on table 2 where component_iD = @@Identity (or component_iD it depends from case, and setting value in @usernameWell, this is a fast solution to this problem, i hope to help someone :) |
 |
|
|
|
|
|
|
|