如 customer变成CU
如果两个单词就取单词首字母 customer code: CC
最后如果结果有重复则试第三个字母
project 和 product 可能就要变成 PR 和 PO
请大侠帮帮忙,谢谢啦
------解决方案--------------------
- SQL code
if object_id('tempdb..#ta')is not null drop table #tacreate table #ta(name varchar(50))insert into #ta select 'customer code'insert into #ta select 'customer'insert into #ta select 'product'insert into #ta select 'product project'insert into #ta select 'product'insert into #ta select 'project';with CET1 as (select distinct name from #ta),CET2 as(select name,upper(left(name,1)+ left(ltrim(stuff(name,1,charindex(' ',name),'')),1 )) as Up from CET1 where ltrim(rtrim(name)) like '% %'union allselect name,Upper(left(name,1) + substring(name,1 + row_number() over(partition by left(name,2) order by (select 1)),1)) from CET1 where ltrim(rtrim(name)) not like '% %')select a.name,b.Up from #ta a,CET2 b where a.name = b.name/*name Up-------------------------------------------------- --------customer code CCproduct project PPcustomer CUproduct PRproduct PRproject PO(6 行受影响)*/
------解决方案--------------------