Here is demonstration of the use of the function charindex to find the section you are looking for.
-- código #1
declare @URL varchar(2000);
set @URL= 'file%3A%2F%2F%2Fmnt%2FABOX%2FRESULTS%2Fresults%2Fresults%2Ftxt%2F20160628105952000_083021988480019_38505_4524425_170_2239408_>>>00001138271467122784<<<<_41_53_ATENDENTE.txt';
PRINT charindex('00001138271467122784', @URL);
The code to search in the rows of a table can be something like:
-- código #2
declare @Txt char(20);
set @Txt= '00001138271467122784';
SELECT URL,
[Posição]= charindex(@Txt, URL)
from tabela;
UPDATING
I have just discovered a pattern the sets I want are between the sixth '_' and the antepenultimate '_' (9 of the count) always so, so I need something to take their position, the sixth and the ninth '_' and between them is the field I want.
Considering the additional explanations about the "_" separator, one can create a specific function to obtain the content between the sixth and ninth "_".
-- código #4 v3
CREATE FUNCTION analisaURL (@pURL varchar(2000))
returns @pToken varchar(200) as
begin
declare @I int, @Pos6 int, @Pos9 int;
-- obtém sexto "_"
set @Pos6= 0;
set @I= 0;
while @I <> 6
begin
set @Pos6= charindex('_', @pURL, (@Pos6 +1));
set @I += 1;
end;
-- obtém nono "_"
set @Pos9= @Pos6;
while @I <> 9
begin
set @Pos9= charindex('_', @pURL, (@Pos9 +1));
set @I += 1;
end;
return substring(@pURL, (@Pos6 +1), (@Pos9 - @Pos6 -1));
end;
go
Carefully evaluate the function code as it has not been tested. It is recommended to add error handling to the function.
The use of the function is thus:
-- código #5
SELECT T.URL, dbo.analisaURL(T.URL) as Token
from tabela as T;
Another option is to use type function split string to split the URL into parts and then select only the seventh part of each URL.
-- código #3 v2
with cteSplitURL as (
SELECT T.URL, S.ItemNumber as seq, S.Item as token
from tabela as T
outer apply dbo.SplitURL(T.URL, '_') as S
)
SELECT URL, token
from cteSplitURL
where seq = 7;
Code #3 is the outline of the code; you must add function of type split string returning tokens and the sequence of it in the string.
Articles containing functions split string:
This example, "00001138271467122784", has neither 127 nor 147 as sequences. More examples?
– Leonel Sanches da Silva
Not that Gypsy, the string size is 165 characters, my example is at initial position 127 and final position 147, but only in this example, in another line the position (location) changes. I want to take the whole set 00001138271467122784 which is always 20 characters. This is the string file%3A%2F%2F%2Fmnt%2FABOX%2FRESULTS%2Fresults%2Fresults%2Ftxt%2F20160628105952000_083021988480019_38505_4524425_170_2239408_>>>>000011371467122784<<<<_41_53_ATENDENTE.txt
– Kaleb Gabriel
Got it. Thanks for clarifying ;)
– Leonel Sanches da Silva