Here's one set-based way to do this; there's probably more efficient ways (i.e., a User-Defined function):-- table of names with no spacesdeclare @Names table ([Name] varchar(100));-- we need a table of numbersdeclare @Ints table (i int identity, [dummy] int);-- here's some datainsert into @Namesselect 'JeffSmith' unionselect 'RobVolk' unionselect 'BillyJoel' unionselect 'MaryJohnson' unionselect 'PetePeters'-- populate our table of numbers with 1-25insert into @ints(dummy)select 0 from @Names N1cross join @Names N2-- this will give us the position of the 2nd capital letter-- in each name:select [Name], Min(i) as PositionFROM @namescross join @intsWHEREi > 1 ANDASCII(SUBSTRING([Name],i,1)) between 65 and 90group by [Name]-- So, our final query is:SELECT Left(Name,Position-1) + ' ' + SUBSTRING(Name,Position, Len(Name)-Position + 1)FROM(select [Name], Min(i) as PositionFROM @namescross join @intsWHEREi > 1 ANDASCII(SUBSTRING([Name],i,1)) between 65 and 90group by [Name]) A
- JeffEdited by - jsmith8858 on 02/17/2003 16:12:16