Hi,@Riyn Pratama
Welcome to the microsoft tsql Q&A forum!
Please check this:
IF OBJECT_ID('view_KDSCMSCNTRCTHHIST')IS NOT NULL
DROP VIEW view_KDSCMSCNTRCTHHIST
GO
CREATE VIEW view_KDSCMSCNTRCTHHIST
AS
SELECT * FROM KDSCMSCNTRCTHHIST
WHERE CNTRCTHHISTCOMP = 'NAV' AND CNTRCTHHISTLNUM=172
WITH CHECK OPTION;
INSERT INTO view_KDSCMSCNTRCTHHIST
SELECT CNTRCTHHISTID+1,
'07-DEC-21', --SCI-SCG5 start date:07-DEC-21
(SELECT CNTRCTHHISTEDATE FROM view_KDSCMSCNTRCTHHIST ), --end date:take from the contract that was previously inputted
CNTRCTHHISTCOMP,
CNTRCTHHISTLNUM,
'SCI-SCG5' --a new location
FROM view_KDSCMSCNTRCTHHIST ;
UPDATE view_KDSCMSCNTRCTHHIST
SET CNTRCTHHISTEDATE = DATEADD(DAY, -1, (SELECT TOP(1)CNTRCTHHISTSDATE FROM view_KDSCMSCNTRCTHHIST ORDER BY CNTRCTHHISTID DESC))
WHERE CNTRCTHHISTSDATE = '25-NOV-21';
Output:
Best regards,
LiHong
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.