Solved

Only need characters to the left of a hyphen

Posted on 2011-03-15
6
414 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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

Introduction In this article, I will by showing a nice little trick for MySQL similar to that of my previous EE Article for SQLite (http://www.sqlite.org/), A SQLite Tidbit: Quick Numbers Table Generation (http://www.experts-exchange.com/A_3570.htm…
More Fun with XML and MySQL – Parsing Delimited String with a Single SQL Statement Are you ready for another of my SQL tidbits?  Hopefully so, as in this adventure, I will be covering a topic that comes up a lot which is parsing a comma (or other…
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.

863 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

18 Experts available now in Live!

Get 1:1 Help Now