GETUTCDATE() return null

  • I have trigger after Insert that update field in the table with GETUTCDATE() but after Insertion I see the value = null

    SET NOCOUNT ON

    UPDATE [dbo].[Employee]

    SET [CurrentDate] = GETUTCDATE()

    FROM inserted

    WHERE inserted.[Id] = [dbo].[Employee].[Id]

  • ali.m.habib (12/18/2013)


    I have trigger after Insert that update field in the table with GETUTCDATE() but after Insertion I see the value = null

    SET NOCOUNT ON

    UPDATE [dbo].[Employee]

    SET [CurrentDate] = GETUTCDATE()

    FROM inserted

    WHERE inserted.[Id] = [dbo].[Employee].[Id]

    It appears that none of that code is the actual problem. Please post all of the code for the trigger.

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

  • I take that back... that's actually an illegal form of update that will sometimes work and sometimes not. I'll explain more after I see the rest of the code for the trigger.

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

  • Jeff Moden (12/18/2013)


    I take that back... that's actually an illegal form of update that will sometimes work and sometimes not. I'll explain more after I see the rest of the code for the trigger.

    I look forward to hearing that explanation.

    In the meantime, wouldn't something like this work?

    SET NOCOUNT ON

    UPDATE a

    SET [CurrentDate] = GETUTCDATE()

    FROM [dbo].[Employee] a

    JOIN inserted b

    ON a.[Id] = b.[Id]


    My mantra: No loops! No CURSORs! No RBAR! Hoo-uh![/I]

    My thought question: Have you ever been told that your query runs too fast?

    My advice:
    INDEXing a poor-performing query is like putting sugar on cat food. Yeah, it probably tastes better but are you sure you want to eat it?
    The path of least resistance can be a slippery slope. Take care that fixing your fixes of fixes doesn't snowball and end up costing you more than fixing the root cause would have in the first place.

    Need to UNPIVOT? Why not CROSS APPLY VALUES instead?[/url]
    Since random numbers are too important to be left to chance, let's generate some![/url]
    Learn to understand recursive CTEs by example.[/url]
    [url url=http://www.sqlservercentral.com/articles/St

  • Jeff Moden (12/18/2013)


    I take that back... that's actually an illegal form of update that will sometimes work and sometimes not. I'll explain more after I see the rest of the code for the trigger.

    I was about to make that same comment but noticed you had. 😉 I know what the problem is but I am having a hard time finding the explanation of why it happens.

    _______________________________________________________________

    Need help? Help us help you.

    Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

    Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.

    Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
    Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
    Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
    Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/

  • Jeff Moden (12/18/2013)


    I take that back... that's actually an illegal form of update that will sometimes work and sometimes not. I'll explain more after I see the rest of the code for the trigger.

    +

    this all what the trigger do no more no less

  • ali.m.habib (12/19/2013)


    Jeff Moden (12/18/2013)


    I take that back... that's actually an illegal form of update that will sometimes work and sometimes not. I'll explain more after I see the rest of the code for the trigger.

    +

    this all what the trigger do no more no less

    You don't understand. I need to see ALL the trigger code because there are other nuances in a trigger that could be important.

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

Viewing 7 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic. Login to reply