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.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Select from another TBL tat has > 1 record

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 AS
SET NOCOUNT ON
DECLARE
@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 INSERTED

OPEN CASH_REC_LINE_INS
FETCH 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 NULL
SELECT @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
END

IF @PACKLIST_STR NOT NULL
BEGIN
UPDATE CASH_RECEIPT_LINE SET REFERENCE = @PACKLIST_STR WHERE INVOICE_ID = @INVOICE_ID
END

DEALLOCATE CASH_REC_LINE_INS


Hope someone can help me..

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2005-09-27 : 01:12:16
See if this helps you
http://sqljunkies.com/WebLog/amachanic/archive/2004/11/10/5065.aspx?Pending=true

Otherwise post some sample data and the result you want


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -