Updating value from the other Date Column in Current Column in same table

Database

Updating value from the other Date Column in Current Column in same table

Hi All,

I am looking for a soultion for below problems statement:

I have three columns in my table

Acct_No.    Snap_Dt             Snap_End_Dt

123            11/17/2015        10/28/2015

123            11/19/2015         11/22/2015

Since the Snap_End_Dt in the first row for 10/28/2015 is wrong. I want to replace the value with Snap_Dt for next date i.e. instead of 10/28/2015 I need to populate it with 11/19/2015 (taking value From Snap_Dt ) in Snap_End_Dt and there are many accounts in my table with similar issues. So this needs to be corrected for all the accounts.

If some can response it be alot appreciated. Thanks much in advance

2 REPLIES
Enthusiast

Re: Updating value from the other Date Column in Current Column in same table

UPDATE TBL FROM

(SELECT ACCT_NO,SNAP_DT,MAX(SNAP_DT)OVER(PARTITION BY ACCT_NO ORDER BY SNAP_DT,SNAP_END_DT) ROWS BETWEEN

1 FOLLOWING AND 1 FOLLOWING) AS CRCTD_DT) B

SET TBL.SNAP_END_DT=B.CRCTD_DT

WHERE TBL.ACCT_NO=B.ACCT_NO

AND TBL.SNAP_DT =B.SNAP_DT

Ca u try this

Re: Updating value from the other Date Column in Current Column in same table

Hi Mani,

Thanks much. This worked

Cheers