×

Good News Everybody!

The new search engine is LIVE!

Please report any problems to david (at) midrange.com.




The first select will work if the Table already exists in Qtemp.   The
second will create a new table BUT if passing in dates, the second will
not work using host variables on a Create Table statement.

1.  Pass in the variables, build the statement in a char string,
prepare, and execute.

OR

2.  Use your select without the where clause to create the table with no
data and then use the first statement to fill:
 CREATE TABLE qtemp/ordtlhst AS (Select * FROM dbmstf/orhdrhst) WITH NO
DATA


David Smith
IT Consultant
dsmith@xxxxxxxxxx

>>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!
>>


As an Amazon Associate we earn from qualifying purchases.

This thread ...


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.