Chad Gray wrote:
> How would I write the SQL to update a record that has the most recent date?
> 
> Say I want to change the status field to "Approved" where the date is the 
> most recent and SKU = 12345
> 
> Will the Max function work in the Where section of the SQL or is there 
> another function to use to find the most recent date?
> 
> UPDATE table 
> SET STATUS = 'approved',
> WHERE SKU = #URL.SKU# AND MAX(StatusWhen)
> 
> 
> Thanks,
> Chad

Something like this usually works

UPDATE table
SET STATUS = 'approved'
WHERE SKU = #URL.SKU#
   AND (
         StatusWhen =
         (
           SELECT TOP 1 StatusWhen
           FROM table
           WHERE SKU = #URL.SKU#
           ORDER BY StatusWhen DESC
         )
       )

Didn't check any of it, but it'll show the idea.

You might wanna use <cfqueryparam /> by the way. If you like your 
night's rest.

Rens

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Message: http://www.houseoffusion.com/lists.cfm/link=i:4:243199
Archives: http://www.houseoffusion.com/cf_lists/threads.cfm/4
Subscription: http://www.houseoffusion.com/lists.cfm/link=s:4
Unsubscribe: 
http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.4
Donations & Support: http://www.houseoffusion.com/tiny.cfm/54

Reply via email to