数据表合并字段,并入数据

select  MZ002 , sa1.tw_Get_userinfo(SUBSTRING(MZ012, CHARINDEX('|',MZ012)+1,10) )+


 sa1.tw_Get_userinfo(SUBSTRING(MZ014, CHARINDEX('|',MZ014)+1,10) ) as checker,  '{$}'+ CONVERT(varchar, MZ013) +'{$}'+ CONVERT(varchar, MZ015) as  checktime


     from   WPURMZ_0629






select * into XMDEV.dbo.WMISMM_20120820 from WMISMM 




insert  into WMISMM select MM002,MM003,MM004,MM005,MM006,MM007,MM008,MM009,MM010,MM011,MM012,MM013,MM014,MM015,MM016,MM017,MM018,MM019,MM020,MM021 from WMISMM_20120820   
  where MM008='新增' or MM008='草稿' or MM008='退回'






  insert  into WMISMM select MM002,MM003,MM004,MM005,MM006,MM007,MM008,MM009,MM010,MM011,MM012,MM013,MM014,MM015,MM016,MM017,sa1.tw_Get_userinfo(SUBSTRING(MM015, CHARINDEX('|',MM015)+1,10) ), '{$}'+ CONVERT(varchar, MM016), '{$}'+ CONVERT(varchar, MM017),MM021 from WMISMM_20120820   
  where MM008='确认' 


  insert  into WMISMM select MM002,MM003,MM004,MM005,MM006,MM007,MM008,MM009,MM010,MM011,MM012,MM013,MM014,MM015,MM016,MM017,
 sa1.tw_Get_userinfo(SUBSTRING(MM015, CHARINDEX('|',MM015)+1,10) )+ sa1.tw_Get_userinfo(SUBSTRING(MM018, CHARINDEX('|',MM018)+1,10) ), 
 '{$}'+ CONVERT(varchar, MM016)+'{$}'+ CONVERT(varchar, MM019),
  '{$}'+ CONVERT(varchar, MM017)+  '{$}'+ CONVERT(varchar, MM020),MM021 from WMISMM_20120820   
  where MM008='审核' 






insert  into WMISMM(MM002,MM003,MM004,MM005,MM006,MM007,MM008,MM009,MM010,MM011,MM012,MM013,MM014,MM015,MM016,MM017,MM018,MM019,MM020 )select MM002,MM003,MM004,MM005,MM006,MM007,MM008,MM009,MM010,MM011,MM012,MM013,MM014,MM015,MM016,MM017,
    
    
 sa1.tw_Get_userinfo(SUBSTRING(MM015, CHARINDEX('|',MM015)+1,10) )+ sa1.tw_Get_userinfo(SUBSTRING(MM018, CHARINDEX('|',MM018)+1,10))+sa1.tw_Get_userinfo(SUBSTRING(MM021, CHARINDEX('|',MM021)+1,10))+sa1.tw_Get_userinfo(SUBSTRING(MM024, CHARINDEX('|',MM024)+1,10) ), 
 
 
 '{$}'+ CONVERT(varchar, MM016)+'{$}'+ CONVERT(varchar, MM019)+'{$}'+CONVERT(varchar, MM022)+'{$}'+CONVERT(varchar, MM025),
  '{$}'+ CONVERT(varchar, MM017)+ '{$}'+ CONVERT(varchar, MM020)+ '{$}'+ CONVERT(varchar, MM023)+ '{$}'+ CONVERT(varchar, MM026) from WMISMM_20120820   
 where MM008='完成' and MM015!=''




    insert  into WMISMM(MM002,MM003,MM004,MM005,MM006,MM007,MM008,MM009,MM010,MM011,MM012,MM013,MM014,MM015,MM016,MM017,MM018,MM019,MM020 )select MM002,MM003,MM004,MM005,MM006,MM007,MM008,MM009,MM010,MM011,MM012,MM013,MM014,MM015,MM016,MM017,
    
    
 sa1.tw_Get_userinfo(SUBSTRING(MM018, CHARINDEX('|',MM018)+1,10))+sa1.tw_Get_userinfo(SUBSTRING(MM021, CHARINDEX('|',MM021)+1,10))+sa1.tw_Get_userinfo(SUBSTRING(MM024, CHARINDEX('|',MM024)+1,10) ), 
 
 
'{$}'+ CONVERT(varchar, MM019)+'{$}'+CONVERT(varchar, MM022)+'{$}'+CONVERT(varchar, MM025),
  '{$}'+ CONVERT(varchar, MM020)+ '{$}'+ CONVERT(varchar, MM023)+ '{$}'+ CONVERT(varchar, MM026) from WMISMM_20120820   




 where MM008='完成' and MM015=''






update WMISMM_20120820  set MM018='',MM019='',MM020='',MM021='',MM022='',MM023='',MM024='',MM025='',MM026='' where MM008='作废'


insert  into WMISMM(MM002,MM003,MM004,MM005,MM006,MM007,MM008,MM009,MM010,MM011,MM012,MM013,MM014,MM015,MM016,MM017) select MM002,MM003,MM004,MM005,MM006,MM007,MM008,MM009,MM010,MM011,MM012,MM013,MM014,MM015,MM016,MM017 from WMISMM_20120820   where MM008='作废' 








select  COUNT(MM002)  , MM002   from WMISMM   where MM002!=''   group by  MM002




select * into XMDEV.dbo.WMISMM_A_20120820 from WMISMM_A
insert  into WMISMM_A(MMA02 ,MMA03,MMA04,MMA05,MMA06,MMA07,MMA08,MMA09,MMA10,MMA11) select MMA02,MMA04,MMA05,MMA06,MMA07,MMA08,'',MMA09,MMA10,MMA12 FROM WMISMM_A_20120820






  

你可能感兴趣的:(SQL,Server,insert)