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

Bulk Insert Query with decimal datatype


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

New User


Joined: 09 Apr 2008
Posts: 83
Location: Chennai

PostPosted: Wed Apr 29, 2009 1:22 pm
Reply with quote

When i am trying to generate bulk insert query using SELECT statement (for few specified columns) from a table, the query is not working if the columns have the following datatypes
1. DATE
2. NUMBER
3. packed decimal

Ex:
SELECT 'INSERT INTO <tb1> VALUES(' || <col1> || ',' ||
col2
|| ')'|| ';'
FROM <tab1> WHERE TIN_NUM = <Tin num>

The col2 column in the above query has packed decimal datatype.
Back to top
View user's profile Send private message
anandinmainframe

Active User


Joined: 31 May 2007
Posts: 171
Location: India

PostPosted: Wed Apr 29, 2009 1:49 pm
Reply with quote

Rahuindo,
Please post(ERRORS or SQLCODES) when you try to insert.
Back to top
View user's profile Send private message
sushanth bobby

Senior Member


Joined: 29 Jul 2008
Posts: 1020
Location: India

PostPosted: Wed Apr 29, 2009 3:52 pm
Reply with quote

Hi rahuindo,

TRY something like this,

Code:
   SELECT 'INSERT INTO <tb1> VALUES('
   || <col1>
   || ','
   || CHAR(col2)
   || ')'
   || ';'
   FROM <tab1>
   WHERE TIN_NUM = <Tin num>


If you get an error, post the ERROR along with column definations.

Thank You,
Sushanth
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Wed Apr 29, 2009 3:59 pm
Reply with quote

It would be a good idea to provide your sql, not the paraphrased in your first post as well as column definitions from ddl.
Back to top
View user's profile Send private message
sushanth bobby

Senior Member


Joined: 29 Jul 2008
Posts: 1020
Location: India

PostPosted: Wed Apr 29, 2009 4:27 pm
Reply with quote

Hello,

My Table details
Code:
Table : Country
ID                              INTEGER
NAME                            CHAR
DESCRIPTION                     CHAR


I tried like this one

Code:
SELECT 'INSERT INTO BOBT1.COUNTRY VALUES('     
||CHAR(ID +1)                                   
||');'                                         
FROM BOBT1.COUNTRY;   


Resulted like
Code:
INSERT INTO BOBT1.COUNTRY VALUES(2          ); 
INSERT INTO BOBT1.COUNTRY VALUES(4          ); 
INSERT INTO BOBT1.COUNTRY VALUES(5          ); 
INSERT INTO BOBT1.COUNTRY VALUES(6          ); 
INSERT INTO BOBT1.COUNTRY VALUES(102        ); 


Thank You,
Sushanth
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Wed Apr 29, 2009 4:31 pm
Reply with quote

Sorry Sushanth,

I posted while you were posting.

my comment was directed to rahuindo.

with luck, you have answered rahuindo's question.
Back to top
View user's profile Send private message
sushanth bobby

Senior Member


Joined: 29 Jul 2008
Posts: 1020
Location: India

PostPosted: Wed Apr 29, 2009 4:37 pm
Reply with quote

Happy to help DINO
Back to top
View user's profile Send private message
rahuindo

New User


Joined: 09 Apr 2008
Posts: 83
Location: Chennai

PostPosted: Thu Apr 30, 2009 1:11 pm
Reply with quote

Thanks to all your advice. The query worked with charm as provided with Susanth.
As adviced, i will write the complete query from next time. Thanks!!
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 Extracting Variable decimal numbers f... DFSORT/ICETOOL 17
No new posts RC query -Time column CA Products 3
No new posts Dynamically pass table name to a sele... DB2 2
No new posts Query on edit primary command CLIST & REXX 5
No new posts Query on edit primary command CLIST & REXX 1
Search our Forums:

Back to Top