3

I have a number of references with a length of 20 and I need to remove the 1st 12 numbers, replace with a G and select the next 7 numbers

An example of the format of the numbers being received

50125426598525412584

I then need to remove first 12 digits and select the next 7 (not including the last)

2541258

Lastly I need to put a G in front of the number so I'm left with

G25412584

My SQL is as follows:

SELECT SUBSTRING(ref, 12, 7) AS ref 
FROM mytable
WHERE ref LIKE '5012%'

The results of this will leave me with

25412584

But how do I insert the G in front of the number in the same SQL statement?

Many thanks

2 Answers 2

3
SELECT 'G'+SUBSTRING(ref, 12, 7) AS ref FROM mytable where ref like '5012%'
Sign up to request clarification or add additional context in comments.

2 Comments

Gabriel, really appreciate your response. I am trying to do an insert based on the results of the select but getting a
what do you have exactly? and does the row actually exist?
1
SELECT CONCAT( 'G', SUBSTRING('50125426598525412584', 13,7)) from dual;

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.