Microsoft SQL Server
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsDatabaseMicrosoft SQL Server

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
  #1  
Old September 14th, 2004, 08:45 PM
zobernjik zobernjik is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Apr 2004
Location: Australia
Posts: 139 zobernjik User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 10 h 31 m 10 sec
Reputation Power: 5
Unhappy create trigger help?

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

Reply With Quote
  #2  
Old September 16th, 2004, 08:34 AM
spungebob spungebob is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Feb 2004
Location: Dover
Posts: 128 spungebob User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 39 sec
Reputation Power: 5
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.

Reply With Quote
  #3  
Old September 16th, 2004, 10:04 PM
zobernjik zobernjik is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Apr 2004
Location: Australia
Posts: 139 zobernjik User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 10 h 31 m 10 sec
Reputation Power: 5
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

Reply With Quote
Reply

Viewing: ASP Free ForumsDatabaseMicrosoft SQL Server > create trigger help?


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway