Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Coping value of one column entry to another of same record ,If the value is null

I have two columns in my table . Code and DocEntery . If DocEntry has value 'NULL' I want it to change to the value of corresponding 'Code' value .There are many rows so could you tell me any query that can be used to update the complete table ? I am using SQL server.

like image 523
mayank sharma Avatar asked Nov 28 '25 13:11

mayank sharma


1 Answers

No need to update the enitre table or use any sort of CASE EXPRESSION or IF, just filter only those will NULL values, and update all of them:

UPDATE YourTable t
SET t.DocEntry = t.Code
WHERE t.DocEntry is null
like image 155
sagi Avatar answered Nov 30 '25 04:11

sagi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!