If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > Update using Substr in SQL

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 04-13-09, 17:15
cboden cboden is offline
Registered User
 
Join Date: Apr 2009
Posts: 2
Update using Substr in SQL

I am new to doing fancy updates and I am in need of help....

I need to change the first four digits in a field. Here is my sql:

update INPT_PKT_hdr
set substr(pkt_ctrl_nbr,1,4) = 'EUAZ'
where substr(pkt_ctrl_nbr,1,4) like 'EUAT%';

can anyone help me?
Reply With Quote
  #2 (permalink)  
Old 04-13-09, 18:43
nidm nidm is offline
Registered User
 
Join Date: May 2003
Posts: 113
Quote:
Originally Posted by cboden
I am new to doing fancy updates and I am in need of help....

I need to change the first four digits in a field. Here is my sql:

update INPT_PKT_hdr
set substr(pkt_ctrl_nbr,1,4) = 'EUAZ'
where substr(pkt_ctrl_nbr,1,4) like 'EUAT%';

can anyone help me?
update INPT_PKT_hdr
set pkt_ctrl_nbr = 'EUAZ' || substr(pkt_ctrl_nbr, 5, ddd)
where pkt_ctrl_nbr like 'EUAT%';


ddd in above substr is the max length of your column pkt_ctrl_nbr

BTW, I changed your predicate by removing the substr to make it more efficiently. Another alternative is:
where substr(pkt_ctrl_nbr, 1,4) = 'EUAT';
Reply With Quote
  #3 (permalink)  
Old 04-13-09, 22:38
cboden cboden is offline
Registered User
 
Join Date: Apr 2009
Posts: 2
Worked like a charm...thank you....
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On