create table #sample(id varchar(100), set_type varchar(100) ,[group] int, Name varchar(100))
insert into #sample(id,set_type,[group])
select '12','Red',1
union all
select '2346','Red',1
union all
select '1235','Green',1
union all
select '12890','Green',1
union all
select '1208','Green',1
union all
select '1234','Green',1
union all
select '908472','Green',2
union all
select '7958326','Blue',1
我需要动态更新表#sample的'名称'列,以便我得到低于所需的结果
Desire result :
insert into #sample(id,set_type,[group],Name)
select '12','Red',1,'red_1_2_25012018'
union all
select '2346','Red',1,'red_1_2_25012018'
union all
select '1235','Green',1,'Green_1_2_25012018'
union all
select '12890','Green',1,'Green_1_2_25012018'
union all
select '1208','Green',1,'Green_3_4_25012018'
union all
select '1234','Green',1,'Green_3_4_25012018'
union all
select '908472','Green',2,'Green_5_5_25012018'
union all
select '7958326','Blue',1,'Blue_1_1_25012018'
更新“名称”列的逻辑:
取set_type = Green:'Name'= Green_1_2_25012018(Id:1235& 12890)和'Name'= Green_3_4_25012018(ID:1208& 1234)
但ID:908472单独留下1 记录所以'Name'= Green_5_5_25012018 Blue只有1条记录 'name'= Blue_1_1_25012018
所以,我想在cte ext之类的集合中执行此UPDATE'name'列,因为我必须更新超过数百万条记录。