• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 431
  • Last Modified:

Only need characters to the left of a hyphen

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
theideabulb
Asked:
theideabulb
  • 3
  • 3
1 Solution
 
jimyXCommented:
update table YourTable set YourField = SubStr(YourField,1,CharIndex('-',YourField)-1)
0
 
theideabulbAuthor Commented:
i am getting an error that

CharIndex does not exist
0
 
jimyXCommented:
It's SubString:
Update YourTable set YourField = SubString(YourField,1,CharIndex('-',YourField)-1)
0
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
theideabulbAuthor Commented:
i changed CharIndex to Locate and that seemed to work just fine
0
 
theideabulbAuthor Commented:
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
 
jimyXCommented:
In MySQL it's Locate, you are absolutely correct, I was thinking MS SQL :-)

Thanks.
0

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now