Edinei Raduvanski Edinei Raduvanski - 7 months ago 12
SQL Question

How to return only records after certain character?

How to return only records after certain character?
Example:

'1-1080599'
'021-1080599'
'02 -1080599 '


Expected outcome:

'1080599'

vkp vkp
Answer

This works if you are looking to extract every character after - and if there is only one - character in the string.

select substring(column1,charindex('-',column1)+1,len(column1)) from tablename
where charindex('-',column1) > 0

or RIGHT can be used.

select right(column1,charindex('-',column1)) from tablename
where charindex('-',column1) > 0