Sql 将A表数据插入到B表

Posted xiaonangua

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Sql 将A表数据插入到B表相关的知识,希望对你有一定的参考价值。

A表和B表字段不同

--insert into B(Name,DepartmentId,DepartmentName,PersonalId,WorkTypeId,CertNumber,CreateTime,Education,IsDel)
select Name,DepartId as DepartmentId,
(select Name from D where IsDisable = 0 and ID = A.DepartId)as DepartmentName,
PersonId as PersonalId,
(select id from W where Name = A.JobName) as WorkTypeId,
CertNumber as CertNumber,
StartDate as CreateTime,--需要转换成datetime类型
(
case ltrim(rtrim(A.Education)) 
when 中专 then 中职(含技工学校) 
when 大专 then 专科(含高职和技师学院) 
when 本科 then 本科及以上  
when 小学 then 小学  
when 初中 then 初中  
when 高中 then 高中  
when 本科及以上 then 本科及以上 
else  ‘‘ end
) as Education,
0 IsDel
from A where id in(
select id from A
where Isdel=0 and IsChangeCert=0
)

 

以上是关于Sql 将A表数据插入到B表的主要内容,如果未能解决你的问题,请参考以下文章