Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 473
  • Last Modified:

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

0
onaled777
Asked:
onaled777
  • 2
  • 2
2 Solutions
 
Bhavesh ShahLead AnalysistCommented:
<CFOUTPUT>
mainly use for printing values of variables.

Plus if use query with cfoutput
<CFOUTPUT QUERY="">

then u have advantage of grouping.
0
 
_agx_Commented:
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">
)



0
 
_agx_Commented:
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.
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now