Solved

cfoutput cfloop syntax question

Posted on 2010-08-16
4
465 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

PROBLEM: How to add your own buttons to the bottom toolbar with paging info ( result count ). While creating a cfgrid, I ran into an issue where I wanted to embed my own custom buttons where the default ones ( insert / delete / etc… ) are for aes…
Recently while working on a project I got a very annoying cfdocument has no body error message. I had never seen this error before. So I checked the code. The code was pretty simple; it was Just showing me the cfdocumnt tag and inside that tag a …
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…

911 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now