Update date In MS SQL

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sibusiso
    New Member
    • Aug 2008
    • 18

    Update date In MS SQL

    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_Timesta mp;
    SET FApplicationnam e = (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
    Recognized Expert Specialist
    • Jun 2007
    • 2878

    #2
    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

    Comment

    Working...