Pages

Thursday, January 23, 2014

populating a table from cfquery result

 this is how you can insert into a table from cfquery resultset.

many insert cfquery will be a bad idea. this is also not a very efficient way but kind of okay.  best thing you can do is to prepare a xml set and insert through  a stored proc through xml insert.

this is easy to do in cf.
1. your query is "qryCodeValue"

<cfsavecontent variable="qryTorun">                     
                    INSERT INTO table (ListNumber,listvalue) VALUES
                    <cfoutput query="qryCodeValue">                                          
                        (#qryCodeValue.ListNumber#, '#qryCodeValue.codevalue#)
                    <cfif qryCodeValue.currentRow EQ qryCodeValue.recordCount>;<cfelse>,</cfif>
                    </cfoutput>
</cfsavecontent>

 <cfquery name="qryRunInsertVar" datasource="#yourDS#">                                                               
              #REReplace(qryTorun,"''","'","ALL")#                          
 </cfquery>


No comments:

Post a Comment