Click here to Skip to main content
15,893,564 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi Team,

I need to iterate replace the first to second column when the condition matchs.

refer the below screenshot

Project

1018439 - 2018 Low Income State Resource
01343-067_Alaska
01343-067_New Hampshire
01343-067_Mississippi
01343-067_District of Columbia
01343-067_New Mexico



batchBookID	                         jf
1018439 - 2018 Low Income State Resource	01343-067_Alaska
	                                        01343-067_New Hampshire
	                                        01343-067_Mississippi
	                                        01343-067_District of Columbia


What I have tried:

for(Map<String,Object> eachRow:tableContent)
            {
                if(eachRow.get("batchBookID")==""){
                    String batchBookID = eachRow2.get("batchBookID").toString();
                    eachRow2.clear();
                    eachRow2.put("batchBookID", batchBookID);
                    eachRow.put("batchBookID", eachRow.get("jf_016"));

}}
Posted
Updated 26-Jan-19 3:44am
Comments
Gssankar 26-Jan-19 8:37am    
I have tried in java but i like to do in mysql since performance is slow

1 solution

Not sure if I understand the question correctly but you probably could use an UPDATE statement. Something like the following

SQL
UPDATE TableName a
SET BatchBookId = '1018439 - 2018 Low Income State Resource'
WHERE (BatchBookId IS NULL OR BatchBookId  = '')
AND EXISTS (SELECT 1
            FROM Project P
            WHERE TableName.JF = p.Column1)

You need to adjust the table and column names to the ones in your database schema.
 
Share this answer
 

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