1

I have a column that consists of details of an orderline named 'ConcatValue'. An example of a value in this column is:

573856014/100/M00558640/OrderQty12 

I want to extract the order value which can be founded after 'OrderQty'. I thought I had a solution by executing the following statement: substr(ConcatValue,char_length(ConcatValue)-1,char_length(ConcatValue))

This results in only level the last 2 characters of the string from the column ConcatValue. For the ConcatValue mentioned above I will get the following result: '12'. Which is the desired result. But when the orderline has an Order quantity below 10, for example in the following ConcatValue:573856014/100/M00558640/OrderQty3

I will get the following result: y3

My question: Is there a way to delete 'y' if a row has an y within the value? Or is there a way to replace the y with a 0? Or is there a way to only select the last digits from the ConcatValue string?

2 Answers 2

1

Use string functions.
With substring_index() you can get the last part of the string and with replace() remove 'OrderQty':

select replace(
         substring_index(ConcatValue, '/', -1),
         'OrderQty',
         ''
       )
from tablename
Sign up to request clarification or add additional context in comments.

Comments

0

Actually, the simplest method is simply:

select substring_index(ConcatValue, 'OrderQty', -1)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.