Skip to content

Instantly share code, notes, and snippets.

@afreeland
Created March 6, 2014 13:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save afreeland/9390169 to your computer and use it in GitHub Desktop.
Save afreeland/9390169 to your computer and use it in GitHub Desktop.
SQL: Common table expression to update a segmented query
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