SQL SERVER 单列多字段拆分到单列多行数据

拆分带,分隔的列至新表中。以下SQL要多次循环执行,直到数量为0时结束 

insert tmplmppzd 
select zwwldw_dwmc,
left(lmppzd_excellm,charindex(',',lmppzd_excellm)-1), left(lmppzd_drplm,charindex(',',lmppzd_drplm)-1)
from tmplmppzd_hua

--更新删除已插入的字段
update tmplmppzd_hua
 set lmppzd_excellm=substring(lmppzd_excellm,charindex(',',lmppzd_excellm)+1,len(lmppzd_excellm)-charindex(',',lmppzd_excellm)),
lmppzd_drplm=substring(lmppzd_drplm,charindex(',',lmppzd_drplm)+1,len(lmppzd_drplm)-charindex(',',lmppzd_drplm))   
--删除已是空的 行数据
delete tmplmppzd_hua where rtrim(lmppzd_excellm)='' or rtrim(lmppzd_drplm)=''

原表的字段:

SQL SERVER 单列多字段拆分到单列多行数据

 调整后的新表格式:

SQL SERVER 单列多字段拆分到单列多行数据