Select a Substring

123 views Asked by At

I found this question and answer on this website which is related to my question.

Except that my problem is that I need to display the information after the "-".

For example, it currently displays 7 - Net 7, 14 - Net 14, 9101 - Net 14, 1 - COD and so on.

I just want it to display the part after the "-".
For instance, I would like it to just display Net 7 or Net 14 or COD.

If I do this:

select distinct right([C].[CustomerTermsCode], charindex(' - ', [C].[CustomerTermsCode]) + 4) AS RightString

It only displays the information before the "-".

Please help me.

1

There are 1 answers

6
Chuck On

You should be using substring, because the length before the dash changes.

select distinct substring([C].[CustomerTermsCode], charindex(' - ', [C].[CustomerTermsCode])+3,50) AS RightString