Larry Brister
asked on
MS SQL cleaner or simplified
My code below works.
It gets the ID and row number
Places into a #temp table
Gets rit of rn=1
And updates my table.
But... is there a more efficient way to do this?
It gets the ID and row number
Places into a #temp table
Gets rit of rn=1
And updates my table.
But... is there a more efficient way to do this?
IF OBJECT_ID('tempdb..#temp') IS NOT NULL
DROP TABLE #temp;
SELECT AccommodationsID ,
ROW_NUMBER() OVER ( PARTITION BY ProspectID ,
TourID
ORDER BY AccommodationsID DESC ) rn
INTO #temp
FROM dbo.everyware_t_accommodations
WHERE User10 <> 'Delete'
ORDER BY AccommodationsID DESC;
DELETE FROM #temp
WHERE rn = 1;
UPDATE a
SET a.User10 = 'Delete'
FROM everyware_t_accommodations a
JOIN #temp t ON a.AccommodationsID = t.AccommodationsID
WHERE 1 = 1;
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER