MVSFORUMS.com Forum Index MVSFORUMS.com
A Community of and for MVS Professionals
 
 FAQFAQ   SearchSearch   Quick Manuals   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

how to insert a value in the middle of a column

 
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Database
View previous topic :: View next topic  
Author Message
rani
Beginner


Joined: 21 Sep 2004
Posts: 2
Topics: 1

PostPosted: Tue Sep 21, 2004 1:22 am    Post subject: how to insert a value in the middle of a column Reply with quote

hi board,

Is there a way to insert a value in middle of a column...if there is a way...how is it possible...

Cheers
Rani
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12378
Topics: 75
Location: San Jose

PostPosted: Tue Sep 21, 2004 5:53 am    Post subject: Reply with quote

rani,

You need to tell us a little bit more. what is the column definiton? is it a char or decimal? Please provide us with a sample input

Kolusu
_________________
Kolusu
www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Siva Kumar Sunku
Beginner


Joined: 17 Aug 2004
Posts: 25
Topics: 14

PostPosted: Fri Sep 24, 2004 4:33 am    Post subject: Reply with quote

Hi Rani,
If the column is char type, following may help you.
Split the column by using Substring function, Reformat/Add (as you need)and again combine them using Concat function.

Ex - If you need to insert 'XYZ' in the column from 3rd position onwards.
Code:

Update <Table_Name>
Set <Col1> = concat( substr(<Col1>,1,2),
                    'XYZ',
                    substr(<Col1>,3,<RestOfColLength>)
                    );


-Siva.
Back to top
View user's profile Send private message AIM Address
astro
Beginner


Joined: 05 Oct 2005
Posts: 31
Topics: 7

PostPosted: Fri Mar 03, 2006 6:19 am    Post subject: Reply with quote

Dear Siva,
Your logic is good. But the scalar function CONCAT can not have more than 2 arguements as you have mentioned in your reply.
If the arguments are more than 2, as in this case, you need to mention as:

Quote:

Update <Table_Name>
Set <Col1> = substr(<Col1>,1,2)
CONCAT 'XYZ'
CONCAT substr(<Col1>,6,<RestOfColLength>)
WHERE
Keycol = :keycol


Hope this will be useful for guys who search this topic in future
Back to top
View user's profile Send private message
shekar123
Advanced


Joined: 22 Jul 2005
Posts: 528
Topics: 90
Location: Bangalore India

PostPosted: Sun Mar 05, 2006 1:27 am    Post subject: Reply with quote

Hi All,

If we had a table named NAME and one of the column had value 'SHEKAR' and if need to introduce '1234' in the middle of the column to get 'SHE1234KAR' ,here is what we get:

Code:

CREATE TABLE SHEKAR.NAME                 
(                                           
 NAME   CHAR(10) NOT NULL,               
)                                           
IN DBTEMP.TBTEMP;                           
INSERT INTO SHEKAR.NAME VALUES ('SHEKAR');


IF WE CODE AS PER SHIVA

Code:

UPDATE SHEKAR.NAME                                         
SET NAME = CONCAT( SUBSTR (NAME,1,3),                       
                   '1234',                                 
                   SUBSTR (NAME,4,3)) WHERE NAME = 'SHEKAR';
WE GET SQL ERROR:
DSNT408I SQLCODE = -170, ERROR:  THE NUMBER OF ARGUMENTS SPECIFIED FOR CONCAT
         IS INVALID     


IF WE CODE AS PER ASTRO

Code:

UPDATE SHEKAR.NAME                                               
SET NAME = SUBSTR(NAME,1,3) CONCAT '1234' CONCAT SUBSTR(NAME,4,3)
WHERE NAME = 'SHEKAR';


OUTPUT

Code:

SHE1234


Shiva and Astro can u please guide me as why i am not getting my desired result as 'SHE1234KAR' ?
_________________
Shekar
Grow Technically
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12378
Topics: 75
Location: San Jose

PostPosted: Mon Mar 06, 2006 9:56 am    Post subject: Reply with quote

shekhar123,

try this

Code:

UPDATE TABLE                                         
   SET NAME = (SELECT SUBSTR(NAME,1,3) CONCAT     
                      CHAR('1234')     CONCAT     
                      SUBSTR (NAME,4,3)           
                 FROM TABLE                         
                WHERE NAME = 'SHEKHAR')           
;                         


Hope this helps...

Cheers

Kolusu
_________________
Kolusu
www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
shekar123
Advanced


Joined: 22 Jul 2005
Posts: 528
Topics: 90
Location: Bangalore India

PostPosted: Mon Mar 06, 2006 11:19 pm    Post subject: Reply with quote

Thanks Kolusu,

I was able to get the desired result.
_________________
Shekar
Grow Technically
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Database All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


MVSFORUMS
Powered by phpBB © 2001, 2005 phpBB Group