• update #temp

    set flag = 'Y'

    from #temp

    join (select lnno ,max(amount) amount from #temp group by lnno) temp2 on

    #temp.lnno = temp2.lnno

    and #temp.amount = temp2.amount