Solved

cfoutput cfloop syntax question

Posted on 2010-08-16
4
469 Views
Last Modified: 2012-05-10
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
Comment
Question by:onaled777
  • 2
  • 2
4 Comments
 
LVL 19

Assisted Solution

by:Bhavesh Shah
Bhavesh Shah earned 500 total points
ID: 33445880
<CFOUTPUT>
mainly use for printing values of variables.

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

then u have advantage of grouping.
0
 
LVL 19

Accepted Solution

by:
Bhavesh Shah earned 500 total points
ID: 33445898
0
 
LVL 52

Expert Comment

by:_agx_
ID: 33447374
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
 
LVL 52

Expert Comment

by:_agx_
ID: 33455854
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

Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The technique is by far very Simple! How we can export the ColdFusion query results to DOC file?  Well before writing this I researched a lot in Internet but did not found a good Answer anyways!  So i thought now i should share my small snippet w…
Hi. There are several upload tutorials using jquery and coldfusion. I found a very interesting one here Upload Your Files using Jquery & ColdFusion and Preview them (http://www.randhawaworld.com/) . I did keep the main js functions but made sever…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question