this code from "slightwv" expert seems work only for the following table
select guid, linkguid, loannumber, lientype, case when linkguid=prev_guid then prev_code else programcode end new_programcode
from (
select guid, linkguid, loannumber, lientype, programcode,
lag(guid) over(order by loannumber asc) prev_guid,
lag(programcode) over(order by loannumber asc) prev_code
from junk
) x;
Example:
Guid LinkGuid LoanNumber LienType ProgramCode
{f1244} {2077a} 123456789 First Lien Bond
{2077a} {f1244} 567345673 Second Lien C30
Result
Guid LinkGuid LoanNumber LienType ProgramCode
{f1244} {2077a} 123456789 First Lien Bond
{2077a} {f1244} 567345673 Second Lien Bond <-- should change to 'Bond'
if the table like the following then the above code won't work.
Example:
Guid LinkGuid LoanNumber LienType ProgramCode
{f1244} {2077a} 123456789 First Lien Bond
{2077a} {f1244} 567345673 Second Lien C30
{4ertw} {w234r} 342342342 First Lien C15
{w234r} {4ertw} 567834566 Second Lien C30
Result
Guid LinkGuid LoanNumber LienType ProgramCode
{f1244} {2077a} 123456789 First Lien Bond
{2077a} {f1244} 567345673 Second Lien Bond <-- should change to 'Bond'
{4ertw} {w234r} 342342342 First Lien C15
{w234r} {4ertw} 567834566 Second Lien C30 <-- no change
Our community of experts have been thoroughly vetted for their expertise and industry experience.
The Most Valuable Expert award recognizes technology experts who passionately share their knowledge with the community, demonstrate the core values of this platform, and go the extra mile in all aspects of their contributions. This award is based off of nominations by EE users and experts. Multiple MVEs may be awarded each year.
This award recognizes a member of Experts Exchange who has made outstanding contributions to the community within their first year as an expert. The Rookie of the Year is awarded to a new expert who has the highest number of quality contributions.