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)
 Stored Procedure to update a datetime field

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
Go to Top of Page

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 = @RecID
GO

--------------------------------------------

This procedure is getting called by a trigger on update:

CREATE TRIGGER [update_status_date] ON [dbo].[NCOS_PLAIN]
FOR UPDATE
AS
EXEC UPDATE_STATUS NC_UNIQUEID

The 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......Thanks



Bryan Holmstrom
Go to Top of Page

Paramasivan B
Starting Member

5 Posts

Posted - 2013-03-15 : 02:41:26


Give the DATETIME DATATYPE for NC_Status_Updated...
just check

Paramasivan B
Go to Top of Page
   

- Advertisement -