sql - Update query from two tables, but some exceptions -


picture(screen shot) http://test.englisheye.co.kr/pic44.jpg

please @ picture above.

i need update table_b table_a t-sql query. (ordinary update 2 tables doesn't work here.)

the question values '4,7' or '5,3'.

i think need create function, don't know start.

please me , thank in advance.

declare @a int, @b nvarchar (20),@c nvarchar (20),@f nvarchar (20),@d int,@e int=1,@g nvarchar(20) set @b='' set  @c='' set @d =1 set  @f='';  create table #mytable (num nvarchar (20),start nvarchar (20) ,[end] nvarchar (20))  while @e<=(select count(*)from table_b) begin set @a= (select (len (num)+1)/2 (select row_number () over(order [start]) id, * table_b)  id=@e) while @d<=@a begin set @b =(select  substring(num,2*@d-1,1) (select row_number () over(order start) id, * table_b)  id=@e) set @c +=(select [end] table_a num =cast (@b int)) +', ' set @f +=(select [end] table_a num =cast (@b int)) +', ' set @d+=1 end set @g = ( select num (select row_number () over(order [start]) id, * table_b) w  id=@e) insert #mytable select @g, left(@c,case when len(@c)>1 len(@c)-1  else len(@c) end ) 'c', left(@f,case when len(@f)>1 len(@f)-1  else len(@f) end ) 'f'  set @b='' set  @c='' set @d =1 set  @f='' set @e+=1 end  update b  set b.start =t.start, b.[end]=t.[end]  table_b b inner join #mytable t on b.num =t.num drop table #mytable 

it's bit complex code works me.


Comments

Popular posts from this blog

Payment information shows nothing in one page checkout page magento -

tcpdump - How to check if server received packet (acknowledged) -