| Author |
Topic |
|
stovan
Starting Member
9 Posts |
Posted - 2010-05-20 : 05:54:50
|
| helpi have data that look like :edward hastingsmatthew brennans cummingshow do split string to get just initial?output :ehmbsc |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2010-05-20 : 05:58:49
|
Won't work for:- 3 part names- 1 part namesHow exactly does your data looks like?Always only 2 part names?Then:selectleft(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. |
 |
|
|
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" |
 |
|
|
stovan
Starting Member
9 Posts |
Posted - 2010-05-20 : 06:02:17
|
| no 3 part :) thank u |
 |
|
|
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] |
 |
|
|
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 allselect 'matthew brennan' union allselect 's cummings') as tMadhivananFailing to plan is Planning to fail |
 |
|
|
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 allselect 'matthew brennan' union allselect 's cummings') as tMadhivananFailing 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. |
 |
|
|
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 |
 |
|
|
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 allselect 'matthew brennan' union allselect 's cummings') as tMadhivananFailing 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 MadhivananFailing to plan is Planning to fail |
 |
|
|
|