Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 sql string

Author  Topic 

stovan
Starting Member

9 Posts

Posted - 2010-05-20 : 05:54:50
help

i have data that look like :

edward hastings
matthew brennan
s cummings

how do split string to get just initial?

output :
eh
mb
sc


webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2010-05-20 : 05:58:49
Won't work for:
- 3 part names
- 1 part names
How exactly does your data looks like?
Always only 2 part names?
Then:
select
left(namecolumn,1)+
substring(namecolumn,charindex(' ',namecolumn)+1,1)
from table


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2010-05-20 : 05:59:47
What about "Peter Larsson Sr"`?
Or "Rev Walter Edges"?



N 56°04'39.26"
E 12°55'05.63"
Go to Top of Page

stovan
Starting Member

9 Posts

Posted - 2010-05-20 : 06:02:17
no 3 part :) thank u
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2010-05-20 : 06:08:14
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=56499


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2010-05-20 : 09:15:37
select data,left(data,1)+substring(data,charindex(' ',data)+1,1) as new_data from
(
select 'edward hastings' as data union all
select 'matthew brennan' union all
select 's cummings'
) as t


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2010-05-20 : 09:45:32
quote:
Originally posted by madhivanan

select data,left(data,1)+substring(data,charindex(' ',data)+1,1) as new_data from
(
select 'edward hastings' as data union all
select 'matthew brennan' union all
select 's cummings'
) as t


Madhivanan

Failing to plan is Planning to fail


Exact my solution...see above


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

Lamprey
Master Smack Fu Yak Hacker

4614 Posts

Posted - 2010-05-20 : 11:01:17
I was just goofing around with PARSENAME for fun..
SELECT 
LEFT(PARSENAME(data, 2), 1)
+ LEFT(PARSENAME(data, 1), 1)
FROM
(
SELECT
REPLACE(data, ' ', '.') AS data
FROM
(
select 'edward hastings' as data union all
select 'matthew brennan' union all
select 's cummings'
) as t
) AS D
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2010-05-21 : 07:10:29
quote:
Originally posted by webfred

quote:
Originally posted by madhivanan

select data,left(data,1)+substring(data,charindex(' ',data)+1,1) as new_data from
(
select 'edward hastings' as data union all
select 'matthew brennan' union all
select 's cummings'
) as t


Madhivanan

Failing to plan is Planning to fail


Exact my solution...see above


No, you're never too old to Yak'n'Roll if you're too young to die.


I didn't read your reply properly

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -