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 2005 Forums
 Transact-SQL (2005)
 Error 209: Ambiguous column name

Author  Topic 

bholmstrom
Yak Posting Veteran

76 Posts

Posted - 2013-03-15 : 09:49:01
This trigger is failing, can anyone see whats wrong?

CREATE TRIGGER [update_status_date] ON [dbo].[NCOS_Data]
FOR UPDATE
AS
Update p
SET NC_Status_Date = getdate(),
NC_Status_Previous = NC_Status
from inserted i
join ncos_data p on p.NC_UniqueID = i.NC_UniqueID

Error is: Error 209 Ambiguous column name 'NC_Status'

Thanks

Bryan Holmstrom

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2013-03-15 : 09:51:11
quote:
Originally posted by bholmstrom

This trigger is failing, can anyone see whats wrong?

CREATE TRIGGER [update_status_date] ON [dbo].[NCOS_Data]
FOR UPDATE
AS
Update p
SET NC_Status_Date = getdate(),
NC_Status_Previous = i.NC_Status
from inserted i
join ncos_data p on p.NC_UniqueID = i.NC_UniqueID

Error is: Error 209 Ambiguous column name 'NC_Status'

Thanks

Bryan Holmstrom




Too old to Rock'n'Roll too young to die.
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2013-03-15 : 09:52:31
but if you really want the previous status then you should use deleted instead of inserted


Too old to Rock'n'Roll too young to die.
Go to Top of Page

bholmstrom
Yak Posting Veteran

76 Posts

Posted - 2013-03-15 : 10:15:43
WebFred

Should I do 2 seperate triggers or 1?

The field NC_Status_Date gets the current datetime when the field is changed, and the NC_Status_Previous should get the previous value of NC_Status if it changed.

Not sure how do this....

Thanks

Bryan Holmstrom
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2013-03-15 : 13:10:45
change inserted with deleted and everything is fine


Too old to Rock'n'Roll too young to die.
Go to Top of Page
   

- Advertisement -