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!

Bulk Insert 1

Status
Not open for further replies.

dasniper

Programmer
Apr 11, 2001
25
0
0
US
I have a textarea on a form that I want to be able to let people put a comma seperated list into, then have CF parse the input and insert all the values into a database.

I'm expecting data like:

Site Code,Site Name <return>

and then I would put it into a database of

ID (generated by database)
SalesID (given by session variable)
Site Code
Site Name

How should I do this? CFLoop the input into seperate chunks with a delimiter of CHR(10)chr(13), then loop through the chunks with an Insert?
 
<cfset myList = form.textarea_contents>

<cfquery datasource=&quot;#datasource#&quot; name=&quot;myQuery&quot;>
INSERT INTO myTable (SalesID, Site_Code, Site_Name)
VALUES(#session.SalesID#, '#ListGetAt(myList, 1)#',
'#ListGetAt(myList, 2)#')
</cfquery>

OR

<cfquery datasource=&quot;#datasource#&quot; name=&quot;myQuery&quot;>
INSERT INTO myTable (SalesID, Site_Code, Site_Name)
VALUES(#session.SalesID#, '#GetToken(myList, 1, &quot;,&quot;)#',
'#GetToken(myList, 2, &quot;,&quot;)#')
</cfquery>

I'm pretty sure either of these would work.
John Hoarty
jhoarty@quickestore.com
 
Yep. I used the first one and it works great.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top