What I am trying to accomplish is to update the ISCURRENT
field to 'N'
and the EFFECTIVE_END_DATE
field to the current date if the record of its type does not have the most recent EFFECTIVE_START_DATE
.
An error does not get thrown it just tells me "0 rows affected" but I created a record with a more recent EFFECTIVE_START_DATE
which should affect the other record in the table that has the earlier EFFECTIVE_START_DATE
.
Here is an image of the 2 records I'm using to test it out.
The record that has a KTEXT
of '400 Atlantic' should be changed from this script to have an ISCURRENT ='N'
and EFFECTIVE_END_DATE=GETDATE()
because the record with the KTEXT
of 500 Maria
has a more recent EFFECTIVE_START_DATE
UPDATE [SAP].[src_gl_sap_m_cepct]
set ISCURRENT='N',
EFFECTIVE_END_DATE=GETDATE()
WHERE NOT EXISTS (SELECT [SPRAS],
[PRCTR],
MAX(EFFECTIVE_START_DATE)
FROM [SAP].[src_gl_sap_m_cepct] AS A
WHERE CONCAT([SAP].[src_gl_sap_m_cepct].[SPRAS],[SAP].[src_gl_sap_m_cepct].[PRCTR]) = CONCAT(A.[SPRAS],A.[PRCTR]
)
GROUP BY [SPRAS],[PRCTR]);
Thank you !