Click here to Skip to main content
15,890,845 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
eid    empname    eaddress
----   --------   ---------
1      venu       hyd
2      ravi       mad
3      kiran      ban
4      raju       hyd

If firstrow in empname column is venu then it has to change all the empname columns values to 'venu' like below table


eid    empname    eaddress
----   --------   ---------
1      venu       hyd
2      venu       mad
3      venu       ban
4      venu       hyd

If firstrow in empname column is NULL then it has to take the 2nd row value and change all empname columns values to 2nd row value i.e 'ravi' like below table




eid    empname    eaddress
----   --------   ---------
1      null       hyd
2      ravi       mad
3      kiran      ban
4      raju       hyd


EXAMPLE



eid    empname    eaddress
----   --------   ---------
1      ravi       hyd
2      ravi       mad
3      ravi       ban
4      ravi       hyd


What I have tried:

I tried with SQL Server update with case statements queries but i didn't get.Can anyone help me with this.
Posted
Updated 22-Jan-19 22:39pm
Comments
CHill60 23-Jan-19 4:38am    
Post the code that you tried that didn't work and we will try to help you fix it

1 solution

That sounds like an odd thing to do, but...
SQL
UPDATE MyTable SET empname = 
   (SELECT TOP 1 empname 
    FROM MyTable
    WHERE empname IS NOT NULL
    ORDER BY eid ASC)
 
Share this answer
 
Comments
Member 13932549 23-Jan-19 4:59am    
Thank you so much OriginalGriff .
OriginalGriff 23-Jan-19 6:14am    
You're welcome!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900