I have searched the internet but couldn't find a solution. I am using the following SQL Statement in order to update some cells or create a new row:
UPDATE [dbo].[PRCRDATALNS]
SET FLD01 = :TIMX1
,FLD02 = :TIML1
WHERE DIM1= :vmtrl AND PRCRULE= '2' AND LINENUM = '1'
IF @@ROWCOUNT=0
INSERT INTO [dbo].[PRCRDATALNS] (
COMPANY
,SODTYPE
,SOTYPE
,PRCRULE
,DIM1
,DIM2
,DIM3
,PRCRDATALNS
,LINENUM
,FROMDATE
,FLD01
,FLD02
,SCALEQTY
)
VALUES
('1'
,'13'
,'1'
,2
,:vmtrl
,'0'
,'0'
,'1'
,'1'
,GETDATE ( )
,:TIMX1
,:TIML1
,'1'
);
When I execute it and a new row is to be inserted it says: The insert statement conflicted with the FOREIGN KEY constraint "XD_PRCRDATALNS_PRCRULE". The conflict occurred in database "KOMBOS", table "dbo.PRCRDATA". The statement has been terminated.
I am aware of what this means. First of all it isn't mentioned anything about issues in columns like others have. And secondly the table PRCRDATA has all the values that are needed like PRCRULE,SODTYPE,SOTYPE etc.
Where should I look at?
I narrowed it down. The message from SQL Server was not right!
It was not PRCRULE the issue. The issue was the FROMDATE that was also a FK and I changed it from GETDATE ()
to CONVERT(DATE, GETDATE())
so I removed the time, and it worked.