SQL 同步更新 记录20230523

--清除临时表1
drop table #temp
--取得休位次数
select * into #temp from (select 
fbarprjcode,fmolotno,fbarfgsize,fbarfgsize2,fsmalltypename,len(fbarfgsize2)-len(replace(fbarfgsize2, '休位', ' ')) as Times from [dbo].[tstkbarprjhdr] where ffgplaneddate>'2023-04-01') as A
--查询休位出现两次
select * from #temp where Times=2

--清除临时表2
drop table #temp2
select * into #temp2 from(select * from #temp where Times=2) as B
--修改休位
update #temp2 set fbarfgsize= replace(fbarfgsize, '+休位','+休位+休位')
--同步更新,注意链表为更新表
--update B SET B.fbarfgsize2=A.fbarfgsize2 FROM #temp2 A INNER JOIN [dbo].[tstkbarprjhdr] B ON A.fbarprjcode=B.fbarprjcode
select * FROM #temp2 A INNER JOIN [dbo].[tstkbarprjhdr] B ON A.fbarprjcode=B.fbarprjcode

 

posted @ 2023-05-23 16:31  microsoft-zhcn  阅读(18)  评论(0)    收藏  举报