By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
460,028 Members | 1,108 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 460,028 IT Pros & Developers. It's quick & easy.

Update date In MS SQL

P: 18
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
Aug 15 '08 #1
Share this Question
Share on Google+
1 Reply


ck9663
Expert 2.5K+
P: 2,878
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
Aug 15 '08 #2

Post your reply

Sign in to post your reply or Sign up for a free account.