Solved

Only need characters to the left of a hyphen

Posted on 2011-03-15
6
417 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
[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
  • 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
Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

 

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

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

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

Suggested Solutions

I have been using r1soft Continuous Data Protection (http://www.r1soft.com/linux-cdp/) for many years now with the mySQL Addon and wanted to share a trick I have used several times. For those of us that don't have the luxury of using all transact…
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…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

749 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