recursion - Recursively updating statement in sql server -



recursion - Recursively updating statement in sql server -

i have table ids varchar(10). possible values

create table temp(id varchar(10)) insert id('01') insert id('011') insert id('0110') insert id('01110') insert id('011111') insert id('02') insert id('020') insert id('0222')

and on .i.e lengths of 2 6. our new requirement says have have decimal after 2 numbers i.e 01 remains same; 011 becomes 011.1; 0110 01.10; 01110 01.11.0 ;011111 01.11.11 manually wrote update statements there 700 such distinct ids how can recursively apply update statement.

thanks

a quick set-based (non-looping) approach utilize case statement this:

update dbo.temp set id = case when len(id) <= 2 id when len(id) between 3 , 4 left(id, 2) + '.' + substring(id, 3, 2) when len(id) between 5 , 6 left(id, 2) + '.' + substring(id, 3, 2) + '.' + substring(id, 6, 2) end;

here's sql fiddle.

sql-server recursion

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -