日期:2014-05-17 浏览次数:20578 次
if object_id('tempdb..#ta')is not null drop table #ta
create 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 all
select 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 CC
product project PP
customer CU
product PR
product PR
project PO
(6 行受影响)
*/