Rotate a column

0

Please login or register to vote for this query.

(click on this box to dismiss)

Stack Overflow

Q&A for professional and enthusiast programmers

DECLARE @ table(x varchar(max),i int identity)
DECLARE @c INT=20

INSERT @ values('12345678901234567890'),('1234567890123456789x')
;WITH C as
(
SELECT row_number() over(order by i)r,count(*)over()c,*
FROM @
WHERE len(x)>@c
), D as
(
SELECT stuff(c.x,@c,1,substring(d.x,@c,1))m,c.i
FROM c,c d WHERE c.r%c.c+1=d.r
)
SELECT * FROM @ z,d WHERE z.i=d.i

Enter Parameters

Options:
Switch to meta site
loading Hold tight while we fetch your results