Created
March 6, 2014 13:53
-
-
Save afreeland/9390169 to your computer and use it in GitHub Desktop.
SQL: Common table expression to update a segmented query
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
with cte | |
as( | |
select ID, AccountID, ItemTypeID, SourceChannelID, ntile(3) over(order by id) as tile_nr from [Item].[Item] where AccountID = 730 | |
) | |
update [item].[item] | |
set SourceChannelID = cte.tile_nr | |
from [item].[item] ii | |
inner join cte on ii.ID = cte.ID | |
where ii.AccountID = 730 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment