Link to home
Start Free TrialLog in
Avatar of onaled777
onaled777Flag for United States of America

asked on

cfoutput cfloop syntax question

Can a cfquery tag be used within a cfoutput tag as shown in the code attached?

If so what is the difference between cfloop instead of cfoutput in the code?



<cfoutput query="GetOrder_id">
			<cfquery name="OrderNotes_ins" datasource="#ARGUMENTS.default_ds#">
				insert into OrderNotes (order_id,ordernote,csr_id)
				values (<cfqueryparam cfsqltype="cf_sql_integer" value="#order_ID#">,'Refund was sent by check',54)
			</cfquery>
		</cfoutput>

Open in new window

SOLUTION
Avatar of Bhavesh Shah
Bhavesh Shah
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
As Brichsoft said, yes you are technically allowed to use a cfquery within a cfoutput. However, since the code doesn't display/output any information to the screen, you don't need a cfoutput. Use a cfloop instead.  

BUT .... having said that, I suspect you may not need a loop at all. If the order id's are stored in another table, the values could be transferred in a single statement:

INSERT INTO OrderNotes (order_id,ordernote,csr_id)
SELECT Order_ID, 'Refund was sent by check',54
FROM    YouOrderTable
WHERE  Order_ID  IN
(
<cfqueryparam value="#listOfOrderIDs#" cfsqltype="cf_sql_integer" list="true">
)



It's not clear what your "real" question is .. ?  But performance wise an insert/select typically gives better performance than *both* of those options (cfloop and cfoutput).  Generally, looping should be avoided whenever possible. Not to mention the fact that looping with separate queries usually requires CFTRANSACTION to ensure data integrity. That isn't being used in the code posted.