Skip to content

Instantly share code, notes, and snippets.

@gavilanch
Created February 3, 2020 22:31
Show Gist options
  • Save gavilanch/2f779fba3a854d38a37a5d7cae6ca06f to your computer and use it in GitHub Desktop.
Save gavilanch/2f779fba3a854d38a37a5d7cae6ca06f to your computer and use it in GitHub Desktop.
Select *, stuff(rango, 1, PATINDEX('%[0-9]%',Rango)-1, '') as Rango_Bonito
from Prueba p
INNER JOIN
(
Select IdCliente,
MAX(CAST(SUBSTRING(stuff(rango, 1, PATINDEX('%[0-9]%',Rango)-1, ''), 0, PATINDEX('%[^0-9]%', stuff(rango, 1, PATINDEX('%[0-9]%',Rango)-1, ''))) AS INT)) as algo3
from Prueba
GROUP BY IdCliente
) t
on p.IdCliente = t.IdCliente and p.Rango like '%' + cast(t.algo3 as nvarchar) + '%'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment