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 2008 Forums
 Transact-SQL (2008)
 Create Join on inserted virtual table

Author  Topic 

ConfusedAgain
Yak Posting Veteran

82 Posts

Posted - 2011-05-23 : 12:05:08
Is this possible?

I have a table that gets updated with a RefID of a record in another table. I want to be able to after Insert, on a trigger, get the RefId from the table that has had the insert and use that RefID to select and insert another record based on some of the data on that record in the original table.

ie:
Table1
RefID Group OriginalGroup
1 A NULL
2 A NULL
3 B NULL


Table 2 gets an insert of RefID = 1,
Table2
RefID Status
1 GroupB

I then want to link to RefID 1 in Table 1 and create a new record in table 1 that would read RefID = 4 (assuming auto incremental ID) and Group = B and OriginalGroup = A

nigelrivett
Master Smack Fu Yak Hacker

3385 Posts

Posted - 2011-05-23 : 12:10:06
create trigger trxxx on T2 after insert
as

insert T2
select ...
from inserted i
join T1 t1
on i.refid = t1.refid


==========================================
Cursors are useful if you don't know sql.
SSIS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page
   

- Advertisement -