Solved

Only need characters to the left of a hyphen

Posted on 2011-03-15
6
413 Views
Last Modified: 2012-05-11
I have a load of product ids that I would like to update and only keep all the characters to the left of the hyphen

Example Product IDS
10012-1
111-2
1322-32

So i want to update a new column that would just be

10012
111
1322

0
Comment
Question by:theideabulb
  • 3
  • 3
6 Comments
 
LVL 24

Accepted Solution

by:
jimyX earned 500 total points
ID: 35142781
update table YourTable set YourField = SubStr(YourField,1,CharIndex('-',YourField)-1)
0
 

Author Comment

by:theideabulb
ID: 35142832
i am getting an error that

CharIndex does not exist
0
 
LVL 24

Expert Comment

by:jimyX
ID: 35142839
It's SubString:
Update YourTable set YourField = SubString(YourField,1,CharIndex('-',YourField)-1)
0
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 

Author Comment

by:theideabulb
ID: 35142847
i changed CharIndex to Locate and that seemed to work just fine
0
 

Author Closing Comment

by:theideabulb
ID: 35142859
Like i mentioned in my other comment.  I changed CharIndex to Locate and it worked perfectly.  Doing a quick search, I am not 100% sure if CharIndex is supported by mysql.  I did not see it come up in the mysql reference.
0
 
LVL 24

Expert Comment

by:jimyX
ID: 35142905
In MySQL it's Locate, you are absolutely correct, I was thinking MS SQL :-)

Thanks.
0

Featured Post

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Join & Write a Comment

Suggested Solutions

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

760 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