Scenario : We have to update the particular column of a table for some rows range. Using csv data file.
Task: we have to update the "Add2" coloumn, add2 data is in cvs file. The previous data in that table should not be disturbed.
Solution: First we have to create temp table for addess.
CMD: db2 create table AddressTemp like Address
It will create table as the same structure as Address.
Now load CVS data in address temp.
CMD: db2 import from C:\test.csv of del insert into AddressTemp (addId,add1,add2,street,city)
It will load the data in Addresstemp Table.
The Update command is :
CMD: db2 update Address set add2= (select add2 from AddressTemp where Address.addid=AddressTemp.addid) where add2 between 103 and 110
Data will be updated from the addresstemp table for add2 coloumn.
Task: we have to update the "Add2" coloumn, add2 data is in cvs file. The previous data in that table should not be disturbed.
Solution: First we have to create temp table for addess.
CMD: db2 create table AddressTemp like Address
It will create table as the same structure as Address.
Now load CVS data in address temp.
CMD: db2 import from C:\test.csv of del insert into AddressTemp (addId,add1,add2,street,city)
It will load the data in Addresstemp Table.
The Update command is :
CMD: db2 update Address set add2= (select add2 from AddressTemp where Address.addid=AddressTemp.addid) where add2 between 103 and 110
Data will be updated from the addresstemp table for add2 coloumn.
| Address Table | ||||
| add id | add1 | add2 | Street | city |
| 100 | samp | samp2 | test | tstcity |
| 101 | samp | samp2 | test | tstcity |
| 102 | samp | samp2 | test | tstcity |
| 103 | samp | samp2 | test | tstcity |
| 104 | samp | samp2 | test | tstcity |
| 105 | samp | samp2 | test | tstcity |
| 106 | samp | samp2 | test | tstcity |
| 107 | samp | samp2 | test | tstcity |
| 108 | samp | samp2 | test | tstcity |
| 109 | samp | samp2 | test | tstcity |
| 110 | samp | samp2 | test | tstcity |
| 111 | samp | samp2 | test | tstcity |
No comments:
Post a Comment