Solved

Extract part of data in a field

Posted on 2013-06-05
3
633 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Enroll in May's Course of the Month

May’s Course of the Month is now available! Experts Exchange’s Premium Members and Team Accounts have access to a complimentary course each month as part of their membership—an extra way to increase training and boost professional development.

Question has a verified solution.

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

Many companies are looking to get out of the datacenter business and to services like Microsoft Azure to provide Infrastructure as a Service (IaaS) solutions for legacy client server workloads, rather than continuing to make capital investments in h…
Azure Functions is a solution for easily running small pieces of code, or "functions," in the cloud. This article shows how to create one of these functions to write directly to Azure Table Storage.
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…

738 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