November 19, 2013 at 3:24 pm
Here's a more concise way to do it. You can update the table by updating the CTE.;-)
WITH CTE AS(
SELECT *, ROW_NUMBER() OVER( PARTITION BY ID ORDER BY ltr) rn
FROM #tmp
)
UPDATE CTE SET
flag = 'Y'
WHERE rn = 1;
If your rank is not ordered alphabetically, you can simply change the column with the CASE statement in the ORDER BY clause
November 20, 2013 at 9:05 am
November 20, 2013 at 9:18 am
You're welcome. I was gladly surprised the first time I realized that I could update/delete a CTE (is mostly like views).
November 21, 2013 at 11:06 am
Of course not all CTEs are going to be updateable, it will depend on the specific coding of the CTE ;-).
SQL DBA,SQL Server MVP(07, 08, 09) "It's a dog-eat-dog world, and I'm wearing Milk-Bone underwear." "Norm", on "Cheers". Also from "Cheers", from "Carla": "You need to know 3 things about Tortelli men: Tortelli men draw women like flies; Tortelli men treat women like flies; Tortelli men's brains are in their flies".
November 22, 2013 at 10:42 am
Luis Cazares (11/19/2013)
Here's a more concise way to do it. You can update the table by updating the CTE.;-)
Put this on the list of things I'm mad I didn't know.
Viewing 5 posts - 1 through 6 (of 6 total)
You must be logged in to reply to this topic. Login to reply