日期:2014-05-18 浏览次数:20699 次
;with cte as
(
select [SRV_PART_NO],
[HW_PART_NO]=substring(case when right([HW_PART_NO],1)=';' then [HW_PART_NO] else [HW_PART_NO]+';' end,1,charindex(';',case when right([HW_PART_NO],1)=';' then [HW_PART_NO] else [HW_PART_NO]+';' end)-1),
col3=stuff(case when right([HW_PART_NO],1)=';' then [HW_PART_NO] else [HW_PART_NO]+';' end,1,charindex(';',case when right([HW_PART_NO],1)=';' then [HW_PART_NO] else [HW_PART_NO]+';' end),'')
from win7_32
union all
select [SRV_PART_NO],[HW_PART_NO]=substring(col3,1,charindex(';',col3)-1),col3=stuff(col3,1,charindex(';',col3),'') from cte
where charindex(';',col3)>0
)
--insert into [Commdity Split] ([HW Part No],[HW_PART_NO])
select distinct [SRV_PART_NO],[HW_PART_NO] from cte
;with cte as
(
select [SRV_PART_NO],
[HW_PART_NO]=cast(substring(case when right([HW_PART_NO],1)=';' then [HW_PART_NO] else [HW_PART_NO]+';' end,1,charindex(';',case when right([HW_PART_NO],1)=';' then [HW_PART_NO] else [HW_PART_NO]+';' end)-1) as varchar(2000)),
col3=cast(stuff(case when right([HW_PART_NO],1)=';' then [HW_PART_NO] else [HW_PART_NO]+';' end,1,charindex(';',case when right([HW_PART_NO],1)=';' then [HW_PART_NO] else [HW_PART_NO]+';' end),'') as varchar(2000))
from win7_32
union all
select [SRV_PART_NO],[HW_PART_NO]=cast(substring(col3,1,charindex(';',col3)-1),col3=stuff(col3,1,charindex(';',col3),'') as varchar(2000)) from cte
where charindex(';',col3)>0
)
--insert into [Commdity Split] ([HW Part No],[HW_PART_NO])
select distinct [SRV_PART_NO],[HW_PART_NO] from cte
------解决方案--------------------