IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Update a certain part of column


IBM Mainframe Forums -> DB2
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
hikaps14

Active User


Joined: 02 Sep 2005
Posts: 189
Location: Noida

PostPosted: Tue May 23, 2006 10:31 am
Reply with quote

Hi,

i want to update a certain part of column .

eg :

there is column NAME (char(20)) .
i want to change first letter of column NAME from 'a' to 'b' .

so i want to know can i use substring command with update .

Thanks in advance,
-Kapil .
Back to top
View user's profile Send private message
Gurmeet

New User


Joined: 22 Feb 2006
Posts: 46
Location: Pune

PostPosted: Tue May 23, 2006 10:16 pm
Reply with quote

Kapil,

User this query,

UPDATE Table_name SET name = 'b' || SUBSTR(name,2)
WHERE name = 'abc';

~Gurmeet
Back to top
View user's profile Send private message
krish_mrt

New User


Joined: 15 Apr 2005
Posts: 12
Location: Chennai

PostPosted: Wed May 24, 2006 2:43 pm
Reply with quote

Hi,
Try this update

Code:
update table_name
set name = 'b'||substr(name,2)
where name like 'a%'
Back to top
View user's profile Send private message
hikaps14

Active User


Joined: 02 Sep 2005
Posts: 189
Location: Noida

PostPosted: Wed May 24, 2006 2:51 pm
Reply with quote

Thanks Buddy .
this seems to be perfect

-Kapil .
Back to top
View user's profile Send private message
rexzone1

New User


Joined: 16 Dec 2006
Posts: 14
Location: Halifax, Canada

PostPosted: Wed Nov 19, 2008 7:46 am
Reply with quote

Hi,

I need to do the same operation(Update particular part of a column) on a numeric field.
Could you please suggest me a way if there is any (without using a program).

Thanks.
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Wed Nov 19, 2008 8:30 am
Reply with quote

Hello,

Possibly, if what you need to do can be accomplished by some calculaton. . .

Otherwise, write the code. . .
Back to top
View user's profile Send private message
hikaps14

Active User


Joined: 02 Sep 2005
Posts: 189
Location: Noida

PostPosted: Wed Nov 19, 2008 7:37 pm
Reply with quote

Well, it would be better if you can provide exact requirement details.

-Thanks,
-Kapil.
Back to top
View user's profile Send private message
Vivek_Vasudevamurthy

New User


Joined: 19 Sep 2008
Posts: 9
Location: Bangalore,Karnataka

PostPosted: Thu Nov 20, 2008 12:08 pm
Reply with quote

Hi friends,

if i want change any letter in center or set of letters how it will work

For a example

"ABCDEF"

now i want to change "CDE" to "XYZ"

==============================
User this query,

UPDATE Table_name SET name = 'b' || SUBSTR(name,2)
WHERE name = 'abc';

in this query what 2 stands for
Back to top
View user's profile Send private message
ashok_uddaraju

New User


Joined: 21 Feb 2007
Posts: 72
Location: US

PostPosted: Thu Nov 20, 2008 1:22 pm
Reply with quote

Let me put in some idea on how the substr command works.

when i say SET name = 'b' || SUBSTR(name,2)

then the the letter 'b' in the first position (i+1) which is 1+1 in this case will be considered.

If you want to change the first two characters it should be

'bc' || SUBSTR(name,3) ----- i+2

One thing i ma not clear is what can be done when we require a substring to slect from some where in the middle.

I assue there should be one more parameter in the SUBSTR command in that case.

Can some body suggest on this?
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Thu Nov 20, 2008 10:50 pm
Reply with quote

Hello,

Something to keep in mind is that many/most data manipulation requirements will not be met by some simple sql query. . .
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> DB2

 


Similar Topics
Topic Forum Replies
No new posts Replacing 'YYMMDD' with date, varying... SYNCSORT 3
No new posts How to load to DB2 with column level ... DB2 6
No new posts RC query -Time column CA Products 3
No new posts first column truncated in search result IBM Tools 13
No new posts Split a record with data in a differe... DFSORT/ICETOOL 8
Search our Forums:

Back to Top