Reputation: 53
I have a table in SQL server with the following rows and columns (A-code, Desc, Length and B-code)
A-Code Desc Length B-Code
A100 Rural-3D 25 A100
A100 NULL 55 B100
** In the first row A-code = B-Code
** In the second A-code<> B-Code and Desc is NULL
What I want to do is update the Desc column of the second row (A-code<> B-Code) with the Desc value from the first row where the A-Code = B-Code
So that my final table result would be as follows
A100 Rural-3D 25 A100
A100 Rural-3D 55 B100
Please help .
Thanks
Upvotes: 1
Views: 889
Reputation: 60493
UPDATE a
SET a.[Desc] = b.[Desc]
FROM MyTable A
INNER JOIN MyTable B on a.[A-Code] = b.[A-Code] and b.[A-Code] = b.[B-Code]
WHERE a.[A-Code] <> a.[B-Code]
And a.[Desc] IS NULL;
Upvotes: 4