I have a list like this thing1,thing2,thing3. And I want to insert them into a look-up table with the same foreign key. So ideally it would look like this:
<cfquery datasource="#ds#" result="insert_things">
INSERT INTO lkp_things (foreign_key, thing) VALUES
(1, thing1), (1, thing2), (1, thing3)
</cfquery>
It seems like the only way to accomplish this is to turn the list into a query, but I'm wondering, is there is a simpler way?
Here's what I've tried:
<cfquery datasource="#ds#" result="insert_things">
INSERT INTO lkp_things (foreign_key, thing) VALUES
<cfloop list="#things#" index="thing">
(#id#,#thing#)<cfif ?????? NEQ len(#things#)>,</cfif>
</cfloop>
</cfquery>
I've heard that you can't do a cfloop inside a cfquery, but I'm not even sure if that's true because I can't have a trailing comma in the VALUES, and I'm not sure how to say "The current iteration number" inside a cfloop. If I turned the list into a query, then I could do currentRow, but again, I'd like to know if there's a simpler way to accomplish this before I go through all that.
Also, I'm using CF 8 and sql server '08 EDIT: Sorry, I'm actually using 2000.