How to get a value in SQL Server Chain

1

I mean, I have a string of numbers that seems like they are not, but a chain is reproduced in the following way:

1881181818181818181800

What I need is to make a selection in the second pair of numbers that would be 81 search for number 81 behind the first 18 if I did so

SELECT Cadena from tabla where cadena like '%81%'

of a table of more than 18000 results I would give

1881181818181818181800
1818181818181818181800
1818181818181818181800
1818181818181818181800

Infinito

Being a single row to recover would be the first but it shows me the numbers 18 as 81 I want something like the subtring (String, 3.2) or idea how would the query to select only numbers 3 and 4 of the first row that would be 81 Help please

They asked me to explain myself better, I think I had done it: if I do:

SELECT Cadena from tabla where cadena like '%81%'

I will get x number of numbers instead of 81 changing the value to one that more than OBVIOUS if it showed the value 81 using the select from above

138113131313131300

I want it is for the chain

188118181818181800

PS I do not want this

SELECT Cadena from tabla where cadena like '%1881'

nor this

SELECT Cadena from tabla where cadena like '%1381'
    
asked by Juan Carlos Villamizar Alvarez 05.09.2016 в 22:29
source

1 answer

2

You can do it in two ways:

Using the substring function:

select Cadena 
  from tabla 
 where substing(Cadena, 3, 2) = '81';

Using like:

select Cadena 
  from tabla 
 where Cadena like '__81%';

If you want to limit the result always to one row, then it would be:

select top 1 Cadena 
  from tabla 
 where Cadena like '__81%';

which will always bring only the first row (although there are thousands that meet the condition).

    
answered by 06.09.2016 / 00:04
source