Home > Ask the AS/400 Experts > DB2/400 and DB2 UDB Questions & Answers > Inserting data from a CTE into a file in SQL
Ask The iSeries 400 Expert: Questions & Answers
EMAIL THIS

Inserting data from a CTE into a file in SQL

Kent Milligan EXPERT RESPONSE FROM: Kent Milligan

Pose a Question
Other iSeries 400 Categories
Meet all iSeries 400 Experts
Become an Expert for this site


iSeries news and advice
Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us    Add to Google


>
QUESTION POSED ON: 24 February 2009
Can I insert data from a CTE into a file? I have this query:
with recursive appidrange ( start, end) as 
(select 4500000, max(apptid) from coprddb3/corcvaptp), 
allIds (apptidlist, endid) as 
( select start as apptidlist, end as endid 
from appidrange union all 
select existing_row.apptidlist + 1 
         existing_row.endid 
from allIds existing_row 
where existing_row.apptidlist +1 <= existing_row.endid), 
missingIds as ( 
select apptidlist from allids 
 except 
select apptid from coprddb3/corcvaptp as temp) 

insert into jgriffin/apptids 
  
select * from missingIds;
As a result of this query, I get an SQL code of: -199 Insert not expected. How can I do this?

>
Since the SQL statement is an INSERT statement, you need to have the common table expression definitions declared with the nested SELECT statement. Here's a simple example:
INSERT INTO out_table 
  WITH my_cte (m1,m2) AS (SELECT absval(col1), absval(col2) FROM my_table ) 
  SELECT m1, m2 FROM my_cte;


Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us    Add to Google



RELATED CONTENT
DB2/400 and DB2 UDB
When is the YES option for 'reuse deleted files' function the best choice?
Monitoring members 'stuck' within a physical file on an EDI system
Developing tables in a parent-child relationship in DB2
SQL server error message -321
Creating a host variable of the 'where in' statement in SQL
Choose which column names are returned via ODBC when working with DB2 files
Allow access to data from a stored procedure result set using COBOL or RPG
Access path and an open data path differences
Convert a numeric physical file to a character in SQL without leading zeros
Implement variables in SQL when creating an alias

iSeries SQL commands and statements
Enhancing RPG with external SQL stored procedures
Tracking data changes on IBM i with triggers
Introduction to SQLRPGLE on IBM i: Making a report
Making the most of RPG data handling on IBM i
When is the YES option for 'reuse deleted files' function the best choice?
Monitoring members 'stuck' within a physical file on an EDI system
Creating a host variable of the 'where in' statement in SQL
SQL server error message -321
Choose which column names are returned via ODBC when working with DB2 files
Convert a numeric physical file to a character in SQL without leading zeros
iSeries SQL commands and statements Research

RELATED RESOURCES
2020software.com, trial software downloads for accounting software, ERP software, CRM software and business software systems
Search Bitpipe.com for the latest white papers and business webcasts
Whatis.com, the online computer dictionary



Search and Browse the Expert Answer Center
Search and browse more than 25,000 question and answer pairs from more than 250 TechTarget industry experts.
Browse our Expert Advice



iSeries Networking - Printing, Remote Access, TCP/IP
HomeNewsTopicsITKnowledge ExchangeTipsBlogsAsk the ExpertsMultimediaWhite PapersProducts
About Us  |  Contact Us  |  For Advertisers  |  For Business Partners  |  Site Index  |  RSS
SEARCH 
TechTarget provides technology professionals with the information they need to perform their jobs - from developing strategy, to making cost-effective purchase decisions and managing their organizations' technology projects - with its network of technology-specific websites, events and online magazines.

TechTarget Corporate Web Site  |  Media Kits  |  Site Map




All Rights Reserved, Copyright 1999 - 2009, TechTarget | Read our Privacy Policy
  TechTarget - The IT Media ROI Experts