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 |
|
Capt_Ron
Starting Member
45 Posts |
Posted - 2006-01-19 : 10:50:26
|
Here's what I have to do:I have a 2 tables tblApproval and tblRequestWhen a record is Inserted into tblApprovalI need to update a record in tblRequestHere are some specifics.I have 2 fields in tblApprovalApproval (can only be "Approved" or Denied") and Department (can only be "Accounting" or "Personnel")I have 2 field in tblRequestAccountingApproval (bit 1 or 0) and PersonnelApproval (bit 1 or 0)IF tblApproval.Department = "Accounting" THEN IF tblApproval.Approval="Approved" THEN SET tblRequest.AccountingApproval = 1 ELSE SET tblRequest.AccountingApproval = 0 END IFELSE IF tblApproval.Approval="Approved" THEN SET tblRequest.PersonnelApproval = 1 ELSE SET tblRequest.PersonnelApproval = 0 END IFEND IF How can I make this into a Trigger so I don't have to code it in the application?Thank you very much for your helpRon |
|
|
shallu1_gupta
Constraint Violating Yak Guru
394 Posts |
Posted - 2006-01-19 : 23:09:38
|
| use a update statement with caseCREATE TRIGGER [TriggerName] ON [dbo].[TblApproval] FOR INSERT, UPDATEASBEGINupdate tblRequest set PersonnelApproval = case inserted.department when 'Accounting' then case inserted.approval when 'Approved' then 1 else 0 end else case inserted.approval when 'Approved' then 1 else 0 end endfrom inserted wheretblapproval.<KeyColumn> = inserted.<Keycolumn>END |
 |
|
|
Capt_Ron
Starting Member
45 Posts |
Posted - 2006-01-23 : 07:59:47
|
| Thank you.I appreciate your help.I'll give it a try.Ron |
 |
|
|
|
|
|