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

theideabulbAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
jimyXConnect With a Mentor Commented:
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: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone 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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.