|
Blue Forest http://www.lslnet.com at 11:08 on July 18, 2006
DB2 Trigger problem Who wrote trigger inserted, I can not write a how ah.
Worried
This is the copy center
- This script has been created using ^ as the termination character.
-- If you wish to execute this script through the CLP, you will need
CLP -- to add the option -td "^" to your command line, for example :
-- Padding -td by "" - f filename.ddl
CONNECT TO SDDATA^
CREATE TRIGGER DB2ADMIN.TI_CARD_ACCT AFTER INSERT ON DB2ADMIN.CARD_ACCT REFERENCING NEW_TABLE AS NEW AS newamount DB2 temp_card_acct MODE FOR EACH ROW
WHEN (newamount = 0)
Insert into temp_card_acct (no_card, PAMT, date_sys)
Select no_card, sum (amount) as PAMT, max (date_sys) as date_sys
From card_acct
Group by no_card;
END^
CONNECT RESET^ |
What 's the error msg?
If the error msg is : "SQL1024N A database connection does not exist. SQLSTATE=08003 "
-- Did you connect to your db first with the correct db name?
If the error msg is : "End of DB21007E reached while reading the command file. "
--did You execute the query using the command : padding -td^-f filename.ddl |
How to change the following sentence into DB2 Trigger? Bit difficult for the trigger that statement n variables, the use of that advice. Help!
Select no_card, sum (amount) as PAMT, max (date_sys) as date_sys
Into #temp_card_acct
From inserted
Group by no_card
If@error<>0
Begin
Raiserror 99999 'This is an error'
Return --rollback transaction
End
Update card_info
Set balance=balance+amt
From #temp_card_acct
Where card_info.no_card=#temp_card_acct.no_card
If@error<>0
Begin
Raiserror 99999 'This is an error'
Return --rollback transaction
End
Update card_info
Set status=inserted.status
From #temp_card_acct, inserted
And where #temp_card_acct.no_card=card_info.no_card
#temp_card_acct.no_card=inserted.no_card And
#temp_card_acct.date_sys=inserted.date_sys
If@error<>0
Begin
Raiserror 99999 'This is an error'
Return --rollback transaction
End |
| |