A Programmer
A Programmer

Reputation: 378

update Query in db2

My table looks like below,

Table Name: Number_List
Columns Name: Num_ID INTEGER 
              First_Number VARCHAR(16) 
              Last_Number VARCHAR(16)

In that, Num_ID is PK. and the rest of the columns First_Number and Last_Number always have a 8 digit number. my requirement is to update that column to 6 Digit entry..

Consider the Entries in the two columns are 32659814 (First_Number) and 32659819 (Last_Number). Now I need to write a update query to change the entries in the table to 326598 (First_Number) and 326598 (Last_Number).

and this table has 15K entries and i need to update the whole in single query in single execution.

Please help me to resolve this.

TIA.

Upvotes: 0

Views: 217

Answers (1)

bhamby
bhamby

Reputation: 15469

All you need is SUBSTR:

UPDATE SESSION.NUMBER_LIST
   SET FIRST_NUMBER = SUBSTR(FIRST_NUMBER, 1,6)
      ,LAST_NUMBER  = SUBSTR(LAST_NUMBER,  1,6)

Upvotes: 1

Related Questions