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 |
|
emman
Starting Member
2 Posts |
Posted - 2012-03-19 : 22:36:17
|
| Hi, I need to update data from a View which contains columns from multiple tables, for example the table has an id number for a field say locationID which is linked to a table with locationID and locationName.I have created an update trigger see below. Is it possible to refer to the Update records using the UPDATE AS U?USE [TESTDB];GOSET ANSI_NULLS ON;GOSET QUOTED_IDENTIFIER ON;GOCREATE TRIGGER [dbo].[trg_UpdateRegister] ON [dbo].[view_Register]WITH EXEC AS CALLERINSTEAD OF UPDATEASBEGIN -- SET NOCOUNT ON added to prevent extra result sets from interfering with SELECT statements. SET NOCOUNT ON; -- Insert statements for trigger hereIF (EXISTS (select E.PersonNumber FROM Employee_Assignment AS E, INSERTED as U WHERE E.PersonNumber = U.PersonNumber)) UPDATE E.Employee_Assignment SET SubmittalDate = U.SubmittalDate, ProposedStartDate = U.ProposedStartDate, ProposedEndDate = U.ProposedEndDate, SubmittedBy = U.SubmittedByFROM INSERTED U WHERE E.assignment_id = U.assignment_id ENDPlease help, I dont know if I am trying to do the impossible. |
|
|
ashishashish
Constraint Violating Yak Guru
408 Posts |
Posted - 2012-03-20 : 00:05:07
|
| Try this way out..UPDATE ESET SubmittalDate = U.SubmittalDate,ProposedStartDate = U.ProposedStartDate,ProposedEndDate = U.ProposedEndDate,SubmittedBy = U.SubmittedByFROM Employee_Assignment E JOIN INSERTED U ON E.assignment_id = U.assignment_id------------------------------------------------The answer is always no till than you don't ask. |
 |
|
|
emman
Starting Member
2 Posts |
Posted - 2012-03-20 : 22:50:11
|
| Thanks very much, this is working now using your suggestion. :) |
 |
|
|
|
|
|