Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove everything before a certain character in SQL Server?

Tags:

sql

sql-server

I have entered data into my SQL server. I want to remove all the characters before a hyphen. There are different amounts of characters before the "-".

For Example:

ABC-123
AB-424
ABCD-53214

I want this result:

123
424
53214

I am new to SQL Server and really need help.
Thank You in advance.

like image 537
Musi Avatar asked Jul 27 '15 20:07

Musi


1 Answers

Try this:

right(MyColumn, len(MyColumn) - charindex('-', MyColumn))

Charindex finds the location of the hyphen, len finds the length of the whole string, and right returns the specified number of characters from the right of the string.

like image 139
APH Avatar answered Oct 03 '22 21:10

APH