Question : SQL Server Triggers for INSERT

I have two tables
first table holds one or more records foe same ClaimID. Each will have a different PRID for a given ClaimID
I have another table with two fields - ClaimID and PrList
I want to write a trigger on the first table that clreates a comma separated list of all the PRIDs of a ClaimID whenever a ClaimID si created and inserts into second table.
The code I have written is attached. I am not sure where I am going wrong.

This is my first Trigger in my entire Database programming experience.

It is working for a ClaimIDs with Single record in the first table. It is not working when I have multiple records for a ClaimID in the first table.

Please let me know if you still need any further details.

Thanks in advance
Pandu

1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
ALTER TRIGGER [dbo].[TR_Prlist]
ON [dbo].[UPReq]
after INSERT
AS
begin
-- SQL Statement or Stored procedure
declare @tempclaimid int
declare @tempPrID bigint
declare @plist as varchar(255)

select @tempclaimid = i.claimid,@tempPrID = i.prid from inserted i

select claimid from PvtPrList where claimid = @tempclaimid

If @@ROWCOUNT = 0
	insert into PvtPrList values (@tempclaimid, CAST(@tempPrID as varchar))
else
	update PvtPrList
    set Prlist = @plist + ',' + CAST(@tempPrID as varchar)
	where claimid = @tempclaimid
end

Answer : SQL Server Triggers for INSERT

You should have to load it at all explicitly. Just make sure it's in the classpath
Random Solutions  
 
programming4us programming4us