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 |
bholmstrom
Yak Posting Veteran
76 Posts |
Posted - 2013-03-14 : 13:37:14
|
Good afternoon,Database="ncos"I have a table with a fields named "unique_id","Status","Status_Updated","Op_Won"What I am looking for is a stored procedure to update the datetime field "Status_Updated" when the field "Status" gets changed.Also, if the field "Status" gets changed to "Won" then I would like to populate the field "Op_Won" with the current datetime.Any ideas...and thanks in advance.Bryan Holmstrom |
|
chadmat
The Chadinator
1974 Posts |
Posted - 2013-03-14 : 13:53:52
|
If you have strict control over the manner in which this table can be modified (Like, it can only go through an SP you write) then you could handle all of that logic in the Stored Proc that modifies that table. But the safer option would be a trigger.-Chad |
|
|
bholmstrom
Yak Posting Veteran
76 Posts |
Posted - 2013-03-14 : 14:51:35
|
I am using a trigger during update but.....here is the story as of now:I have a procedure:CREATE PROCEDURE [UPDATE_STATUS] (@RecID int)AS Update ncos_Plain SET NC_Status_Updated = getdate()WHERE NC_UniqueID = @RecIDGO--------------------------------------------This procedure is getting called by a trigger on update:CREATE TRIGGER [update_status_date] ON [dbo].[NCOS_PLAIN] FOR UPDATEASEXEC UPDATE_STATUS NC_UNIQUEIDThe system throws an error:Error converting data type nvarchar to int.The field nc_uniqueid is a integer.Beyond that I would REALLY only like to update the field when one fields is altered.Any thoughts ideas......ThanksBryan Holmstrom |
|
|
Paramasivan B
Starting Member
5 Posts |
Posted - 2013-03-15 : 02:41:26
|
Give the DATETIME DATATYPE for NC_Status_Updated...just checkParamasivan B |
|
|
|
|
|