Error when creating an UPDATE Trigger in SQL

I am trying to create a trigger on a table (RM00102) when Column (USERDEF1) is updated so it will add the current date to Table (SSGRM001) column (CustUpdDate). but when I fire the trigger with a change to USERDEF1 i get the following error
"a save operation on table RM_Customer_MSTR_ADDR failed because a database constraint was violated"

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE TRIGGER [dbo].[trg_SSGRM001_CUSTUPD] ON [dbo].[RM00102] 
	AFTER UPDATE 
AS 
set nocount on 
IF UPDATE(USERDEF1)
BEGIN 
UPDATE D
SET D.CustUpdDate = GETDATE() 
FROM   RM00102 A INNER JOIN
SSGRM001 D ON A.CUSTNMBR = D.CUSTNMBR 
END 
set nocount off
GO

Open in new window

skull52IT director Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

JesterTooCommented:
That error message does not appear to originate from this trigger... what is "RM_Customer_MSTR_ADDR" and how does it relate to this transaction?
0
skull52IT director Author Commented:
"RM_Customer_MSTR_ADDR"  is the name used in Dynamics GP for table RM00102
0
JesterTooCommented:
Please check the table definition to see what constraints have been declared and check your data to determine what constraint is being violated.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
10 Tips to Protect Your Business from Ransomware

Did you know that ransomware is the most widespread, destructive malware in the world today? It accounts for 39% of all security breaches, with ransomware gangsters projected to make $11.5B in profits from online extortion by 2019.

skull52IT director Author Commented:
I was using SET D.CustUpdDate = GETDATE() but should have been using
 SET SSGRM001.CustUpdDate = (SELECT  DATEADD(d, DATEDIFF(d, 0, GETDATE()), 0) AS Expr1)
I missed that.
0
Scott PletcherSenior DBACommented:
Or just CAST it as date:

SET D.CustUpdDate = CAST(GETDATE()  AS date)
0
skull52IT director Author Commented:
Scott, Yeah... that would be less complicated, thanks
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server

From novice to tech pro — start learning today.