Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Replace everything after a space in a string

Posted on 2004-04-20
4
Medium Priority
?
527 Views
Last Modified: 2012-06-27
HI,
As the replace fn does not accept wildcards, how do I remove all characters in a string, AFTER the first space is encountered?
Ie; the original string may read: SONY ELECTRONICS
What I want this to be replaced with is simply: SONY

thanks!
Fergal
0
Comment
Question by:fjkilken
[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
  • 2
4 Comments
 
LVL 8

Expert Comment

by:Dishan Fernando
ID: 10867044
can you explan little more
You want this.
"SONY ELECTRONICS" --> "ELECTRONICS" ???
0
 
LVL 43

Expert Comment

by:TimCottee
ID: 10867091
Hi fjkilken,

How about

Left(MyField,CharIndex(' ',MyField)-1)

Tim Cottee
Brainbench MVP for Visual Basic
http://www.brainbench.com
0
 

Author Comment

by:fjkilken
ID: 10867232
The solution: "Left(MyField,CharIndex(' ',MyField)-1)" probably won't work as I do not know how many characters ( for the CHAR INDEX) will be in the string, ie; it could be SONY ELECTROINCS or just as easilt: PHILIPPS INDUSTRIES
0
 
LVL 43

Accepted Solution

by:
TimCottee earned 1000 total points
ID: 10867259
fjkilken,

That is the point, CharIndex tells you where the first space is in the string then takes everything to the left of that. Of course if it is an empty string it will fail but you can simply handle that with:

Left(MyField + ' ',CharIndex(' ',MyField + ' ') -1)

Tim.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
An alternative to the "For XML" way of pivoting and concatenating result sets into strings, and an easy introduction to "common table expressions" (CTEs). Being someone who is always looking for alternatives to "work your data", I came across this …
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

636 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