I need to create an output file with selected records from an input file,
but the records to select depend on a date range from a related file.  This
sounded to me like an ideal thing for SQL.

Looking up online how to do it, I found the SELECT INTO with examples of
creating an output table, so I thought I'd try it:

SELECT * INTO qtemp/ordtlhst FROM dbmstf/ordtlhst WHERE onrcu IN (SELECT
onrcu FROM dbmstf/orhdrhst WHERE shpdtiso >= '2006-03-13' AND shpdtiso <=
'2006-03-17')

That doesn't work, however, because the i5 is expecting a host variable, I
think, after the SELECT INTO.  Must be that different versions of SQL want
different things.

I found, in the archives, this way to do it:

CREATE TABLE qtemp/ordtlhst AS (Select * FROM dbmstf/ordtlhst WHERE onrcu IN
(SELECT onrcu FROM dbmstf/orhdrhst WHERE shpdtiso >= '2006-03-13' AND
shpdtiso <= '2006-03-17')) WITH DATA

That worked!  Id this the 'proper' SQL statement to do this?  I'm ultimately
going to be passing the dates in as parms.

Thanks!


This thread ...

Follow-Ups:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2026 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.