• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

update based on ordered data

Explorer ,
May 30, 2006 May 30, 2006

Copy link to clipboard

Copied

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>
TOPICS
Advanced techniques

Views

166

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
May 30, 2006 May 30, 2006

Copy link to clipboard

Copied

LATEST
Try replacing the CFLOOP with <CFOUTPUT QUERY="target">, and the </CFLOOP> with </CFOUTPUT>. Set onerow to 0 before you enter the CFOUTPUT and increment it at right before </CFOUTPUT>

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation