Solved

Extract part of data in a field

Posted on 2013-06-05
3
622 Views
Last Modified: 2013-12-25
Hi Experts,

i am interested in extracting part of data in a field. the field data as below

Charles.David Charles David
Tom.Thomas Tom Thomas
Mannasseh.Abdul Mannasseh Abdul

i do not require the data after the space. The desired data is as below

Charles.David
Tom.Thomas
Mannasseh.Abdul

A simple solution is desired
Thanks in advance
0
Comment
Question by:Peter Kiprop
3 Comments
 
LVL 16

Accepted Solution

by:
Surendra Nath earned 500 total points
ID: 39221298
a charindex in combination with the substring will solve this for you

declare @t varchar(100) = 'Charles.David Charles David'
select substring(@t,1,CHARINDEX(' ',@t)-1)

Open in new window

0
 
LVL 48

Expert Comment

by:PortletPaul
ID: 39221323
a tiny addition to the above which will avoid a possible problem if no space is found in the string... deliberately add a space, then look for a space. Only the position of the first space is returned by charindex so the result is the same as the above - except it won't error if the actual string has no space in it.

declare @t varchar(100) = 'Charles.DavidCharlesDavid'
select substring(@t,1,CHARINDEX(' ',@t+' ')-1)
0
 
LVL 6

Author Closing Comment

by:Peter Kiprop
ID: 39221361
Work great. though i did some modifications to suit what i wanted. Many thanks
0

Featured Post

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Read about achieving the basic levels of HRIS security in the workplace.
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now