Solved

Replace everything after a space in a string

Posted on 2004-04-20
4
477 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
  • 2
4 Comments
 
LVL 8

Expert Comment

by:dishanf
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 250 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

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

Everyone has problem when going to load data into Data warehouse (EDW). They all need to confirm that data quality is good but they don't no how to proceed. Microsoft has provided new task within SSIS 2008 called "Data Profiler Task". It solve th…
JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.
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.

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

22 Experts available now in Live!

Get 1:1 Help Now