|
|
|||||||||
|
|||||||||
|
|||||||||
| |
||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
I have a table that has a number of data fields,I need to be able to capture datatime when the date field was entered or entered value changed.I was told I need to create a trigger on that table that contains all the fields.
I have seen the syntax for creating triggers, and read some documentation but I am still in the dark as how to create what I need to. I was hoping to see if somebody had a similar example or an advice, anything is more than what I have at the moment. This is what I was able to come up with so far. CREATE TRIGGER NotifyDateFieldUpdates ON RelocateeRemovalist For INSERT, UPDATE, DELETE AS DECLARE @RemovalistNumber VARCHAR(200) DECLARE @RelocateID INT /*InspectionDate */ DECLARE getInsp CURSOR FOR SELECT RelocateID,RemovalistNumber FROM INSERTED a LEFT JOIN DELETED b ON (a.RemovalistNumber=b.RemovalistNumber and a.RelocateID=b.RelocateID) WHERE a.InspectionDate IS NOT NULL AND b.InspectionDate IS NULL OPEN getInsp FETCH NEXT FROM getInsp INTO @RelocateID, @RemovalistNumber WHILE (@@FETCH_STATUS <> -1) BEGIN INSERT INTO RelocateeRemovalistFieldEntry(RElocateID, RemovalistID)SELECT RelocateID,RemovalistID FROM INSERTED a LEFT JOIN RelocateeRemovalistFieldEntry b ON (a.RelocateID=b.RelocateID AND a.RemovalistNumber=b.RemovalistNumber)WHERE b.RElocateID is null UPDATE RelocateeRemovalistFieldEntry SET InspectionDateDateTime=GETDATE() WHERE RelocateID=@RelocateID aND RemovalistNumber=@RemovalistNumber FETCH NEXT FROM getInsp INTO @RelocateID, @RemovalistNumber END DEALLOCATE getInsp GO but when I check the syntax it gives me an error " Ambiguous column name "RelocateID. and "Ambiguous column name "RemovalistNumber", it don't know what is the message of this error, what needs to be fixed, couldn't find much help on it either. Regards and thanks |
|
#2
|
|||
|
|||
|
Ambiguous column name
When you are dealing with more then one table and they use the same names you get this error Ambiguous column name .
You need to specify table name infront of these fields. |
|
#3
|
|||
|
|||
|
Thanks for your reply, I have realized that, and that part is fine,but what do you think about the trigger I am trying to create here, if you understand what I need to do and why am i doing this.
Haven't been able to find many examples for triggers, it is all mainly very simeple stuff.....nothing about capturing dates at all. Regards |
![]() |
| Viewing: ASP Free Forums > Database > Microsoft SQL Server > create trigger help? |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|