View previous topic :: View next topic |
Author |
Message |
vkphani Intermediate

Joined: 05 Sep 2003 Posts: 483 Topics: 48
|
Posted: Tue Nov 08, 2005 2:24 am Post subject: Updating a particular byte of a field in a table |
|
|
Hi !!
I want to update the 3rd byte of a character field in a table with character |
|
Back to top |
|
 |
Phantom Data Mgmt Moderator

Joined: 07 Jan 2003 Posts: 1056 Topics: 91 Location: The Blue Planet
|
|
Back to top |
|
 |
vkphani Intermediate

Joined: 05 Sep 2003 Posts: 483 Topics: 48
|
Posted: Tue Nov 08, 2005 3:11 am Post subject: |
|
|
Yes Phantom,
I too searched for this in the forum. But didn't get any results.
Anyway thanks for the help. |
|
Back to top |
|
 |
Phantom Data Mgmt Moderator

Joined: 07 Jan 2003 Posts: 1056 Topics: 91 Location: The Blue Planet
|
|
Back to top |
|
 |
kolusu Site Admin

Joined: 26 Nov 2002 Posts: 12378 Topics: 75 Location: San Jose
|
Posted: Tue Nov 08, 2005 5:25 am Post subject: |
|
|
vkphani,
Try this untested sql
Code: |
UPDATE TABLE
SET UPD_COL = SUBSTR(UPD_COL,1,1) CONCAT
SUBSTR(UPD_COL,2,1) CONCAT
CHAR('A',1) CONCAT
SUBSTR(UPD_COL,4,1) CONCAT
SUBSTR(UPD_COL,5,1)
;
|
Hope this helps...
Cheers
Kolusu _________________ Kolusu
www.linkedin.com/in/kolusu |
|
Back to top |
|
 |
Phantom Data Mgmt Moderator

Joined: 07 Jan 2003 Posts: 1056 Topics: 91 Location: The Blue Planet
|
Posted: Tue Nov 08, 2005 5:31 am Post subject: |
|
|
Kolusu,
I thought (very vaguely remember) I saw some string function to replace a particular position(s) of the string - directly. And you were the one who gave that solution. I don't know where and when I saw that. Isn't there any other way to accomplish this.
Thanks,
Phantom |
|
Back to top |
|
 |
kolusu Site Admin

Joined: 26 Nov 2002 Posts: 12378 Topics: 75 Location: San Jose
|
Posted: Tue Nov 08, 2005 5:35 am Post subject: |
|
|
Phantom,
Replace Function works for the entire column and if the string is known. However in this case the 3rd byte is unknown.
I guess you are referring to the solution posted in here
http://www.mvsforums.com/helpboards/viewtopic.php?p=15976#15976
Quote: |
I don't know where and when I saw that. Isn't there any other way to accomplish this.
|
Could be , but at the top of my head right now , I could only think of that
Kolusu _________________ Kolusu
www.linkedin.com/in/kolusu |
|
Back to top |
|
 |
vkphani Intermediate

Joined: 05 Sep 2003 Posts: 483 Topics: 48
|
Posted: Tue Nov 08, 2005 5:56 am Post subject: |
|
|
Thanks for the help Kolusu.
Kolusu,
Is there any specific reason behind mentioning so many CONCAT statements in the query.
Even the below query works.
Code: | UPDATE TABLE
SET UPD_COL = SUBSTR(UPD_COL,1,2) CONCAT
CHAR('A',1) CONCAT
SUBSTR(UPD_COL,4,5); |
|
|
Back to top |
|
 |
kolusu Site Admin

Joined: 26 Nov 2002 Posts: 12378 Topics: 75 Location: San Jose
|
Posted: Tue Nov 08, 2005 6:01 am Post subject: |
|
|
Quote: |
Is there any specific reason behind mentioning so many CONCAT statements in the query.
|
Vkphani,
NO reason ! I just got up and was thinking of taking 1 byte at a time and that reflected in my query. Just an early morning blues.
Kolusu _________________ Kolusu
www.linkedin.com/in/kolusu |
|
Back to top |
|
 |
vkphani Intermediate

Joined: 05 Sep 2003 Posts: 483 Topics: 48
|
Posted: Tue Nov 08, 2005 6:02 am Post subject: |
|
|
Thanks for the help Kolusu. |
|
Back to top |
|
 |
Rahull Beginner

Joined: 29 Jan 2004 Posts: 62 Topics: 19
|
Posted: Mon Nov 28, 2005 3:16 pm Post subject: |
|
|
How will i do the same(Update any byte) if my column data type is S9(13) COMP-3. |
|
Back to top |
|
 |
kolusu Site Admin

Joined: 26 Nov 2002 Posts: 12378 Topics: 75 Location: San Jose
|
Posted: Mon Nov 28, 2005 3:44 pm Post subject: |
|
|
Rahull,
If the update column is decimal column , then you need to expand it and then update it.
ex: assume the following data
Code: |
Upd_col
-+-----
123456
234567
345678
|
Now if I want to update the 2 byte of upd_col with a constant 9, then the following sql will give you the desired results.
Code: |
UPDATE TABLE
SET UPD_COL = DEC(SUBSTR(DIGITS(UPD_COL),1,8) CONCAT
SUBSTR(DIGITS(INT(9)),10,1) CONCAT
SUBSTR(DIGITS(UPD_COL),10,4))
;
|
This will result in
Code: |
Upd_col
-+-----
193456.
294567.
395678.
|
Hope this helps...
Cheers
kolusu _________________ Kolusu
www.linkedin.com/in/kolusu |
|
Back to top |
|
 |
|
|