onaled777
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?
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>
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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.
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"
)