Mark,
Since tableA and tableB use the same REQUEST.dsn1, you can try this:

<cfquery name="insertRecords" datasource="#REQUEST.dsn1#">
Insert into INTO tableB (fieldnameA, fieldnameB, fieldnameC)
SELECT T.field1, T.field2, T.field3
FROM tableA T
WHERE T.userID = <cfqueryparam cfsqltype="cf_sql_int"
value="#FORM.userID#">
</cfquery>

Hua

-----Original Message-----
From: Mark Leder [mailto:[EMAIL PROTECTED]
Sent: Friday, May 28, 2004 12:15 PM
To: CF-Talk
Subject: Looping a returned query to insert into another table

Hi all,

I've never done this before, but how do you loop a query of, say 6
records, and rewrite the output into another table?

1) Retrieve the records:
<cfquery name="getRecords" datasource="#REQUEST.dsn1#">
SELECT T.field1, T.field2, T.field3
FROM tableA T
WHERE T.userID = <cfqueryparam cfsqltype="cf_sql_int"
value="#FORM.userID#">
</cfquery>

3) Here's the table to insert the records to:
<cfquery name="putRecords" datasource="#REQUEST.dsn1#">
INSERT INTO tableB
(fieldnameA, fieldnameB, fieldnameC)
VALUES (#getRecords.field1#, #getRecords.field2#,
#getRecords.field3#)
</cfquery>

Thanks, Mark
[Todays Threads] [This Message] [Subscription] [Fast Unsubscribe] [User Settings]

Reply via email to