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
 Other SQL Server 2008 Topics
 Trigger in 2008

Author  Topic 

lamine
Starting Member

1 Post

Posted - 2013-04-30 : 10:44:43
I would like to have an AFTER UPDATE, INSERT Trigger.
I have two tables:

Jobs has three fields; JobsId, JobsName, JobsArea
JobsLink has three fields; JobsLinkId, JobsLinkJobsId, JobsLinkCalculation.

The two tables are linked ON Jobs.JobsId = JobsLink.JobsLinkJobsId

What I want is? If I update Jobs table or insert a new records in it, I want it to update or insert a records in JobsLink where JobsLinkCalculation field will simply have JobsName + '-' + JobsArea from jobs table.

Please help.
Cheers
L

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-05-02 : 01:39:15
[code]
CREATE TRIGGER Trg_CreateJobLink ON Jobs
AFTER INSERT
AS
BEGIN

INSERT JobsLink(JobsLinkJobsId, JobsLinkCalculation)
SELECT JobsId,JobsName + COALESCE('-' + JobsArea ,'')
FROM INSERTED

END
[/code]

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page
   

- Advertisement -