sql - update first 10 rows with one value and next 10 with another -


i have table members

members  id      data 1         2         3         4         b 5         b 6         b 7         b 

here , want 1st 3 id's updated a, next 3 id's b , next 3 , on. please me in sql.

thanks in advance.

this should work (assuming sql server 2005+):

;with cte1 (     select  *,             id2 = row_number() over(order id) - 1     yourtable ), cte2 (     select  *,              id2/3%2 n     cte1 ) update cte2 set data = case when n = 0 'a' else 'b' end;  select * yourtable 

here sqlfiddle demo.


Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -