Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Remove all characters to the left of a specified character

Posted on 2011-03-08
2
Medium Priority
?
348 Views
Last Modified: 2012-05-11
I have a column of data that has text like "New Price, now only $5.99"  

I would like to remove all the characters to the left of the dollar sign.

It would leave only the $5.99
0
Comment
Question by:theideabulb
2 Comments
 
LVL 16

Expert Comment

by:sjklein42
ID: 35075992
Something like this should do it:

SUBSTRING ( mystring , CHARINDEX ( mystring, '$' ), 10 )

Open in new window

see:

CHARINDEX ( expression1 ,expression2 [ , start_location ] )

http://msdn.microsoft.com/en-us/library/ms186323.aspx

SUBSTRING ( expression ,start , length )

http://msdn.microsoft.com/en-us/library/ms187748(v=sql.90).aspx
0
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 2000 total points
ID: 35082889
sjklein: the question is for MySQL, not mssql server.

the logic is the same, though, using the INSTR or LOCATE functions
http://dev.mysql.com/doc/refman/5.0/en/string-functions.html#function_instr
http://dev.mysql.com/doc/refman/5.0/en/string-functions.html#function_locate

and the substr / mid function(s):
http://dev.mysql.com/doc/refman/5.0/en/string-functions.html#function_mid
http://dev.mysql.com/doc/refman/5.0/en/string-functions.html#function_substring

watch out though about the order of the arguments in INSTR vs LOCATE (vs CHARINDEX), it's not always the same !
0

Featured Post

Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

Question has a verified solution.

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

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…
Recursive SQL is one of the most fascinating and powerful and yet dangerous feature offered in many modern databases today using a Common Table Expression (CTE) first introduced in the ANSI SQL 99 standard. The first implementations of CTE began ap…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

885 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