Chad,
You can do a sub query:
UPDATE table
SET STATUS = 'approved',
WHERE SKU = #URL.SKU# AND StatusWhen =
(
SELECT MAX(StatusWhen) FROM table
)
But it might be better to make something with more feedback:
// Declare the ID to be updated
DECLARE @id INT;
// Get the ID to be updated
SET @id = ISNULL(
(
SELECT [id] FROM table
WHERE SKU = #URL.SKU# AND
StatusWhen = ( SELECT MAX(StatusWhen) FROM table )
),
0
)
// Update the table
UPDATE table
SET STATUS = 'approved',
WHERE [id] = @id
// Return the updated record id
SELECT
@id
This of course assumes you have some sort of ID column.
.......................
Ben Nadel
www.bennadel.com
-----Original Message-----
From: Chad Gray [mailto:[EMAIL PROTECTED]
Sent: Monday, June 12, 2006 10:45 AM
To: CF-Talk
Subject: SQL question
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
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Message: http://www.houseoffusion.com/lists.cfm/link=i:4:243200
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=89.70.4
Donations & Support: http://www.houseoffusion.com/tiny.cfm/54