How to update corresponding records as exactly same based on other column

Raj0125 511 Reputation points
2023-06-19T09:52:53.69+00:00

Hi,

I am using below sql to update Effective_Start_Date as same as updated_date for each source_id.But i am not not able to get it.

Here i have Source_Id having duplicates with different Updated_date

WITH CTE AS (

SELECT *, ROW_NUMBER() OVER (PARTITION BY Source_Id order by Updated_date ) As rn

from Declaration_Backup]

where Effective_Start_Date IS NULL

)

Update CTE

SET Effective_Start_Date = Updated_date

Sample data:

User's image

Need to change as below

User's image

Please suggest how to chnage sql.

Please suggest how to chnage sql.

SQL Server | Other
{count} votes

Answer accepted by question author
  1. Wilko van de Velde 2,241 Reputation points
    2023-06-19T10:53:09.8533333+00:00

    Maybe I don't understand the problem, but isn't it just:

    Update Declaration_Backup
    SET Effective_Start_Date = Updated_date
    where Effective_Start_Date IS NULL
    
    1 person found this answer helpful.
    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.