Richard Cooper wrote:
> hi all,
> 
> just looking at this query and thought there must be a better way of writing 
> it. I'm probabley missing something obvious, here's the code:
> 
> <cfquery name="editAllPages" datasource="#REQUEST.theDatabase#">
> UPDATE        corpPages
> SET           priority = priority - 1
> WHERE active = '1'
> AND           subpage = (SELECT       subpage FROM corppages  pageID = 
> <cfqueryparam value="#ARGUMENTS.pageID#" cfsqltype="cf_sql_integer" />)
> AND           isFloat = '0'
> AND           navlocation = (SELECT   navlocation FROM corppages      pageID 
> = <cfqueryparam value="#ARGUMENTS.pageID#" cfsqltype="cf_sql_integer" />)
> AND           siteLocation = (SELECT  sitelocation FROM corppages     pageID 
> = <cfqueryparam value="#ARGUMENTS.pageID#" cfsqltype="cf_sql_integer" />)
> AND           priority > (SELECT      priority FROM corppages pageID = 
> <cfqueryparam value="#ARGUMENTS.pageID#" cfsqltype="cf_sql_integer" />)
> </cfquery>                            
> 

This might be a little easier to read and maintain....

<cfquery name="editAllPages" datasource="#REQUEST.theDatabase#">
UPDATE corpPages
SET corpPages.priority = corpPages.priority - 1
FROM corpPages a LEFT JOIN corpPages ON a.subpage = corpPages.subpage
AND a.navlocation = corpPages.navlocation
AND a.sitelocation = corpPages.sitelocation
WHERE corpPages.active = '1'
AND corpPages.isFloat = '0'
AND corpPages.priority > a.priority
AND a.pageID = <cfqueryparam value="#ARGUMENTS.pageID#" 
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:259390
Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm
Unsubscribe: 
http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.4

Reply via email to