Connecting Tech Pros Worldwide Help | Site Map

Update date In MS SQL

Newbie
 
Join Date: Aug 2008
Posts: 18
#1: Aug 15 '08
HI

Can Any one help

I have extra field on a table like
FDate, FYear, FMonth, FDay, FDatename

I have a triger that I will update this field every time transaction hapened, this field must be updated to the curent date, year, month, date name

I wrote something like.

CREATE TRIGGER tr_Test3
ON dbo.TTest3
FOR INSERT,UPDATE
AS
BEGIN
SET NOCOUNT ON;

UPDATE TTest3
SET FCreatedBy = System_User

WHERE FID = (SELECT FID FROM inserted);

UPDATE TTest4
SET FCurentUser = System_User;

UPDATE TDates
SET Fdatetime = Current_Timestamp;
SET FApplicationname = (SELECT App_Name());
SET Fdatetime = (SELECT GetDate());
SET FYear = (SELECT Year(GetDate()));
SET FMonth = (SELECT Month(GetDate()));
SET FDay = (SELECT Day(GetDate()));
SET FDatename = (SELECT Datename(Month,GetDate()));
END

I find the Error:

Incorrect syntax near '=' line 18
Incorrect syntax near '=' line 19
Incorrect syntax near '=' line 20
Incorrect syntax near '=' line 21
Incorrect syntax near '=' line 22
Incorrect syntax near '=' line 23

Can Any on help how can I update the table with this values.

Thanks
ck9663's Avatar
Expert
 
Join Date: Jun 2007
Posts: 1,925
#2: Aug 15 '08

re: Update date In MS SQL


Too many "SET".

Check the syntax here

Also, you might just want to define these as DEFAULT VALUES and use the trigger not to allow changes.

-- CK
Reply