Richard Cooper wrote:
> Hi All,
> 
> How would I turn this into an SQL while loop rather than a nested query? I 
> never used while loops and can't quite suss it. 
> 
> Here's the code:
> 
> <!--- Select the priority of this service --->
> <cfquery name="getAllServices" datasource="#REQUEST.theDatabase#">
> SELECT        priority, serviceID
> FROM  TPSservices
> WHERE active = '1'
> AND           priority > <cfqueryparam value="#getDeletedPrior.priority#" 
> cfsqltype="cf_sql_integer" />
> </cfquery>
> 
> <!--- Loop over the services --->
> <cfloop query="getAllServices">
> <cfset newPriority = #priority# - 1>
> <cfquery name="getAllServices" datasource="#REQUEST.theDatabase#">
> FROM  TPSservices
> SET           priority = <cfqueryparam value="#newPriority#" 
> cfsqltype="cf_sql_integer" />
> WHERE serviceID = <cfqueryparam value="#serviceID#" 
> cfsqltype="cf_sql_integer" />
> </cfquery>
> </cfloop>
> 

I don't think you need to use any loops in sql...I believe the following 
would do the same thing as your code above....

<cfquery name="getAllServices" datasource="#REQUEST.theDatabase#">
UPDATE TPSservices
SET priority = priority - 1
WHERE active = '1' AND priority > <cfqueryparam 
value="#getDeletedPrior.priority#" cfsqltype="cf_sql_integer" />
</cfquery>

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Introducing the Fusion Authority Quarterly Update. 80 pages of hard-hitting,
up-to-date ColdFusion information by your peers, delivered to your door four 
times a year.
http://www.fusionauthority.com/quarterly

Archive: 
http://www.houseoffusion.com/groups/CF-Talk/message.cfm/messageid:258364
Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4

Reply via email to