Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

inserting multiple rows (from a loop..)

Status
Not open for further replies.

gadjodilo77

Programmer
Sep 23, 2005
79
0
0
NL
If you see the following thread:
You see at the bottom the results. They are being showed in a loop:

<cfoutput>#myString# / #typenumber# / #codenumber#</cfoutput><br>

How can I insert these loop results into another database table? row by row?

Like this:

auto_id column1 column2 column3
1 value1(myString) value1(typenumber) value1(codenr
2 value2(mystring) value2(typenumber) value2(codenr)

etc....

I tried something like this:

<CFQUERY NAME="update" DATASOURCE="rug">
INSERT INTO dev
(
<CFLOOP query="q">

dev_volgnr <CFIF #currentrow# NEQ #q.recordcount#>,</cfif>

</cfloop>
)
VALUES
(

<CFLOOP query="q">
'#myString#' <CFIF #currentrow# NEQ #q.recordcount#>,</cfif>
</cfloop>

)
</CFQUERY>

But that doesn't work!!

Is there a solution?

Gr, Kabbi
 
Look into constructing an INSERT statement based on this structure:

INSERT INTO MyTable(field1,field2,field3)
SELECT '#field1val#','#field2val#','#field3val#'
UNION
SELECT ...(repeat as necessary for each row in your OUTPUT loop)

Phil Hegedusich
Senior Programmer/Analyst
IIMAK
-----------
Eschewing obfuscation diurnally.
 
Hi, Thank you.

But how would I repeat this for each row?
 
Use CFLOOP to construct the INSERT statement.

Phil Hegedusich
Senior Programmer/Analyst
IIMAK
-----------
Eschewing obfuscation diurnally.
 
Yes, thank you. I already figured it out... did not expect it to be easy like that.

Grt
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top