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 |
|
doristan
Starting Member
12 Posts |
Posted - 2005-09-26 : 23:55:46
|
| I want to write a trigger that when i save, it will check on other tableB(based on an Aid, eg: Invoice ID), there may have more than one line/record that has the same Aid, here i want to select all the Bid that has the same Aid and concatenates it.I am still a beginner in writting trigger, so.. really have no idea on this..CREATE TRIGGER INS_PACKLIST_CASH_REC_LINE ON CASH_RECEIPT_LINE FOR INSERT, UPDATRE ASSET NOCOUNT ONDECLARE@INVOICE_ID VARCHAR(15)@CUST_ORDER_ID VARCHAR(15)@PACKLIST_NO INT@CNT INT@PACKLIST_ID VARCHAR(15)@PACKLIST_STR VARCHAR(50)DECLARE CASH_REC_LINE_INS CURSOR LOCAL FOR SELECT INVOICE_ID FROM INSERTEDOPEN CASH_REC_LINE_INSFETCH CASH_REC_LINE_INS INTO @INVOICE_ID***i have no idea with the following code, i based on VB Script to write and i know its not correct.IF @INVOICE_ID NOT NULLSELECT @PACKLIST_NO = COUNT(*) FROM RECEIVABLE_LINE WHERE INVOICE_ID = @INVOICE_ID iF @PACKLIST_NO > 0 BEGIN FOR @CNT = 1 TO @PACKLIST_NO SELECT @PACKLIST_ID = PACKLIST_ID FROM RECEIVABLE_LINE WHERE INVOICE_ID = @INVOICE_ID AND LINE_NO = @CNT @PACKLIST_STR = @PACKLIST_STR + @PACKLIST_ID NEXT ENDIF @PACKLIST_STR NOT NULL BEGIN UPDATE CASH_RECEIPT_LINE SET REFERENCE = @PACKLIST_STR WHERE INVOICE_ID = @INVOICE_ID ENDDEALLOCATE CASH_REC_LINE_INSHope someone can help me.. |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
|
|
|
|
|