I want to find out the number between 3 and 4 Identifier like # or @ in given String

Viewed 25

I Have a Unique key column like

ABCDRF#72665523975#1769#00177#001#2779#NA#Pyddfdfdfd#CAOHGHGHG

in which we have composite few columns and we separated by #.
From this composite key I want to find out the number between 3 and 4 separate

I have used substring with charindex-string-functions-in-sql-queries, but not able to find out the expected results.

I want to find out 00177 from above

1 Answers

Knowing the position, you can do it using MySQL SUBSTRING_INDEX function:

SET @str = 'ABCDRF#72665523975#1769#00177#001#2779#NA#Pyddfdfdfd#CAOHGHGHG';
SET @pos = 4

SELECT SUBSTRING_INDEX(
    SUBSTRING_INDEX(@str, '#', @pos), 
    '#', -1
);
Related