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
 General SQL Server Forums
 New to SQL Server Programming
 History Table

Author  Topic 

m7mdadil
Starting Member

3 Posts

Posted - 2011-01-18 : 01:22:30
Hello ,,
How to get the updated column value and insert this updated value into another table ..
In other meaning; I want to create History table to have ALL the changes that happens in a column value ..
Thanks in advance

m7mdadil
Starting Member

3 Posts

Posted - 2011-01-18 : 01:26:52
I know that I must use a trigger, but my problem is how to get the updated value, and insert it to the History table ...

mohamedadel
Go to Top of Page

m7mdadil
Starting Member

3 Posts

Posted - 2011-01-18 : 03:36:04
HORAAAY I DID IT
below my solution to your benifit

Create Trigger trg
On Projects
For Update, Insert
As
if UPDATE(ProjectStatusId)
Begin
--Insert Into ProjectStatusesHistory (ProjectId,inserted, StatusDate)
Insert StatusesHistory (ProjectId, StatusId, StatusDate, MainUL, MainUH, MainDT)
Select ProjectId, ProjectStatusId, StatusDate, UL, UH, DT From inserted
End

mohamedadel
Go to Top of Page
   

- Advertisement -