December 18, 2013 at 5:43 pm
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]
December 18, 2013 at 8:12 pm
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
Change is inevitable... Change for the better is not.
December 18, 2013 at 8:14 pm
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
Change is inevitable... Change for the better is not.
December 18, 2013 at 11:03 pm
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 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
December 19, 2013 at 7:28 am
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/
December 19, 2013 at 7:32 am
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
December 21, 2013 at 10:23 am
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
Change is inevitable... Change for the better is not.
Viewing 7 posts - 1 through 6 (of 6 total)
You must be logged in to reply to this topic. Login to reply