Solved

Only need characters to the left of a hyphen

Posted on 2011-03-15
6
416 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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 

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

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…
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

840 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