QUERY SQL - Separate String

0

I am working with some queries and the need has arisen to have to stay with only a part of a field, that is, I have a field that has a final extension similar to this 13123243534.Consumo and at the same time other values in that Same field but of different length, I tried to use a SUBSTRING but I have to specify where it starts to cut but having different length does not help me.

I do not know if anyone knows any way to remember from point .Consumo until the end but can only cut Consumo without the point.

    
asked by Paulo Rodriguez 09.08.2017 в 14:52
source

2 answers

4

Test using the T-SQL functions CHARINDEX and LEFT / RIGHT :

Help page

CHARINDEX searches for the position of the character you want to search.

LEFT and RIGHT subscribe to the address of the instruction.

The example I would give you to solve your problem would be the following:

SELECT RIGHT('13123243534.Consumo', LEN('13123243534.Consumo') - CHARINDEX('.','13123243534.Consumo'))

//Recortamos por la derecha el largo del texto menos el índice de la posición del 
  punto, de esta manera obtienes el largo de la palabra colocada a la derecha

I hope it serves you.

    
answered by 09.08.2017 в 15:04
2

You can use the CHARINDEX function to know the position of the '.' and do the substring from there.

SELECT SUBSTRING(campo,CHARINDEX('.', campo)+1,100) as camp FROM tabla
    
answered by 09.08.2017 в 15:08