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 > using update to increment a varchar by 1

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 12-15-09, 12:36
cgjoker cgjoker is offline
Registered User
 
Join Date: Jan 2007
Posts: 4
using update to increment a varchar by 1

I am trying to figure out the sql that can give me the following.

Increment a value of say, 001, by 1 for a field that is a varchar.

Im thinking something like this but its incorrect.

update table set CAST(varchar_field AS INTEGER)=001 + 1 where ....

thanks.
Reply With Quote
  #2 (permalink)  
Old 12-15-09, 13:22
ARWinner ARWinner is offline
Registered User
 
Join Date: Jan 2003
Posts: 3,575
You want something like: update mytable set varchar_col = char(integer(varchar_col) + 1) where ...

Be warned that if the column has non-numeric data it will fail.

Andy
Reply With Quote
  #3 (permalink)  
Old 12-15-09, 14:32
cgjoker cgjoker is offline
Registered User
 
Join Date: Jan 2007
Posts: 4
sounds good, ill try that out.

thanks !
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