Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsGeneralPHPASPPerlColdFusionFlashHTML, CSS, ScriptsBrowsers

Webmaster Forum / ColdFusion / Advanced Techniques / May 2006



Tip: Looking for answers? Try searching our database.

update based on ordered data

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
muellertj - 30 May 2006 18:36 GMT
I need to update a field in the database based on an ordered query.  The
problem I am having is that the updated field (targetvalue) is not updating the
right record in the database.  I need the targetvalue to insert into the
database so that the highest targetvalue is with the highest drymatter and the
lowest targetvalue is with the lowest drymatter.

Here is the code so far.  It is creating the targetvalues and updating the
database.  It just isn't doing it in the correct order.

<cfquery name="target" datasource="Dairy">
SELECT *
FROM dairy.dbo.paddockdata
WHERE FarmID='#form.farmid#'
AND DataDate=#DateValue#
ORDER BY drymatter DESC
</cfquery>
<cfset M=(2750-1100)/(0-#form.numrows#)>

<CFLOOP INDEX="onerow" FROM="0" TO="#target.recordcount#">
<cfset targetvalue=(M*(1+#onerow#))+2750>
<CFQUERY NAME="insertvaluedata" DATASOURCE="dairy">
UPDATE dairy.dbo.paddockdata
SET targetvalue= #TargetValue#
WHERE ID=#target.ID#
</CFQUERY>
</CFLOOP>
jdeline - 30 May 2006 20:12 GMT
Try replacing the CFLOOP with <CFOUTPUT QUERY="target">, and the </CFLOOP> with </CFOUTPUT>
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.